Documentation

REST API

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 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 <=
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 Post with id 1
.../posts?createdAt_order=desc Posts sorted by createdAt
.../posts?category_eq=one Posts in category one
.../posts?title_contains=hello Posts with title containing hello
.../posts?_limit=5&views_order=desc Top 5 posts sorted by views
.../posts?isDraft_eq=false&views_lt=100 Published posts with less than 100 views
.../posts?_offset=20&_limit=10 Page 2 with 10 results per page

Nested resources

See relations.