Routes¶
Routes are defined in a single json
file.
The routes.json file¶
This file is mandatory but you can customize its name in the .drosserc.js
file (see Configuration). This is where you define all the routes you want to mock. Each route is defined as a tree, with slash as separator.
Woot ? Tree ? Slash ? I just want to mock a couple of routes...
Ooook, an example worth a thousand sentences of bad explanation. Let's say you want to mock these 2 routes:
You would create a tree in your routes.json
file like this:
That's what we mean by "a tree". We consider that an API can be completely described in such a structure.
Okay, but where do the actual mocks go ? And if have a GET AND a POST on
/api/users
?
Good questions, thanks for asking.
The DROSSE object¶
That's where the DROSSE
object comes in and saves our souls. Look at this:
Everything happens inside the DROSSE
object. You can insert a DROSSE
object anywhere in the tree. A DROSSE
object can contain HTTP verbs, like in the above example and a couple of other keys (more on these later).
I WANT TO MOCK MY ROUTES!!! WHERE DO I PUT MY MOCKED CONTENTS???
There we go! You can mock your datas in 3 different ways:
- directly inside the
routes.json
file, using thebody
key (see Inline mocks). - in a static JSON file with a constrained name (see Static mocks)
- in a dynamic JS file (we consider it a service) with a constrained name (see Dynamic mocks)
But before we move to the mock contents, let's have a look to the other stuffs you can put into the DROSSE
object.