Stubbing - SoftwareSandbox/FiAngulartje GitHub Wiki
Stubbing out the backend
Because we want to develop our front-end completely separately from our back-end, we wanna stub out the entire back-end. I did some research on the internets and came up with a couple of possibilities.
Option #1: Write your own back-end stub with express.js
Using grunt-connect
's middleware you can basically build your own server stub that you can code completely to your own desires/necessities.
Pros
You're completely in charge of everything: not too much magic, completely customizable, ...
Cons
Because you're in charge of everything you'll also need to configure all the things. Responses, Error responses, which I guess would eventually lead into making a more configurable stub anyways, so why reinvent the wheel here?
Option #2: Prism
Prism is a library which allows you to record all requests and responses to a real back-end, to then use those recordings as your stubbed back-end. There's a grunt-prism
project that allows you to use Prism as middleware to grunt-connect
.
Pros
Would be absolutely great if you have a completely working back-end already. So this is ideal to develop your front-end versus existing API's like Twitter, or Github, or Twitch, or ...
Cons
Since we don't have a fully functional back-end and we need to basically "dream up" our API and returned JSON responses, this is not ideal for us. Although the library allows you to use it like this. See this issue, and maybe more in general this documentation.
Furthermore Prism doesn't launch an actual server, it merely proxies all requests to a certain url:port/path. So we'd miss out on failing fast on CORS stuff.
Option #3: Stubby
Stubby allows you to configure requests and responses based on request matching. It also comes with a grunt task.
Pros
- Very easily configurable json responses that we can keep in separate files
- Starts an actual server
Cons
Starting up a server slows the application down a little bit.