Routes

Sub-routes and nested resources

You can define sub-routes like this:

routes:
    - path: "/users"
    - path: "/users/{id}"
    - path: "/users/{user_id}/orders"
    - path: "/users/{user_id}/orders/{id}"

json-mockr will identify 2 resources (users & orders) and filter the data based on the path variables defined.

- GET "/users/ABC/orders"

will filter all Orders than contain a field named user_id with values ABC

- GET "/users/ABC/orders/XYZ"

will find an Order than contains a field named user_id with values ABC and a field Id with XYZ

It's also possible to define a path variable that targets a nested object using the @ separator, ex:

  • request `GET /users/ABC/orders to defined route:
    - path: "/users/{user@id}/orders"
    

in this case we filter all Orders than contain an object named user with an id field inside with value ABC

Authorization

You can define Authorization per route

routes:
    - path: "/users"
      authorization: Basic

The server will respond with a 401 UNAUTHORIZED if no valid authorization header exists.

Possible authorization values are: Basic, Bearer, None