Overview
Endpoints are automatically created based on the models in your config.
This is best explained with an example. Let's consider Mockend's own .mockend.json
(opens in a new tab) used in our demo. It contains Post
and Comment
models with some fields and relations.
Note that model names must be CamelCased and singular.
mockend.yml
models:
Post:
hasMany: [Comment]
fake:
_count: 10
cover: { imageURL: [1920, 1080] }
title: { loremWords: [3, 10] }
body: loremParagraphs
category: { stringOf: [one, two, three] }
isDraft: { bool: 90 }
views: { int: [0, 1000] }
createdAt: dateTime
Comment:
belongsTo: [Post]
fake:
_count: 25
email: email
body: loremParagraphs
createdAt: { dateTime: [2010-01-01T00:00:00Z, 2020-12-31T23:59:59Z] }
Endpoints
Mockend will automatically create Post
and Comment
endpoints.
GET .../posts
GET .../posts/:id
POST .../posts
PUT .../posts/:id
PATCH .../posts/:id
DELETE .../posts/:id
GET .../comments
GET .../comments/:id
POST .../comments
PUT .../comments/:id
PATCH .../comments/:id
DELETE .../comments/:id
Note that POST/PUT/PATCH/DELETE
are completely mocked endpoints. You or your users can freely call these endpoints without having to worry about data getting dirty.
Query
Resources can be queried, filtered and sorted using various query parameters.
Operators
Param | Description |
---|---|
<field>_eq | == |
<field>_ne | != |
<field>_gt | > |
<field>_gte | >= |
<field>_lt | < |
<field>_lte | <= |
Search
Param | Description |
---|---|
<field>_contains | field contains string |
<field>_startsWith | field starts with string |
<field>_endsWith | field ends with string |
Sort
Param | Description |
---|---|
<field>_order=asc|desc | sort array |
Paginate
Param | Description |
---|---|
_limit | number of items in array |
_offset | start of array |
Example requests
Here are some working examples to get you started.
URL | Description |
---|---|
.../posts/1 (opens in a new tab) | Post with id 1 |
.../posts?createdAt_order=desc (opens in a new tab) | Posts sorted by createdAt |
.../posts?category_eq=one (opens in a new tab) | Posts in category one |
.../posts?title_contains=hello (opens in a new tab) | Posts with title containing hello |
.../posts?_limit=5&views_order=desc (opens in a new tab) | Top 5 posts sorted by views |
.../posts?isDraft_eq=false&views_lt=100 (opens in a new tab) | Published posts with less than 100 views |
.../posts?_offset=20&_limit=10 (opens in a new tab) | Page 2 with 10 results per page |
Nested resources
See relations.