Skip to content
Ruben Vicario Gonzalez edited this page Mar 7, 2015 · 22 revisions

Non-persistent endpoint

Create a route

Input the name of the route you want to create

Click on the + button

Insert your data

Change your data

How to access the data

Do a HTTP request at http://mockr-hr.herokuapp.com/1/:username/:route with the verb where you inserted the information at Mockr.

Ex: If you selected 'GET' and inserted at least the status code and data, you can do a GET request to your endpoint and have that data returned.

-GET http://mockr-hr.herokuapp.com/1/james/comments

Persistent endpoint

Create a route

Input the name of the route you want to create

Click on the + button

How to work with your endpoint

-Get all the data: GET http://mockr-hr.herokuapp.com/1/:username/:route

Ex: GET http://mockr-hr.herokuapp.com/1/james/comments

### Params you can pass

**-createdAt**

  Values: ASC(default), DESC

  Ex: http://mockr-hr.herokuapp.com/1/james/comments?createdAt=DESC

**-updatedAt**

  Values: ASC(default), DESC

  Ex: http://mockr-hr.herokuapp.com/1/james/comments?updatedAt=ASC

**-start**

  Values: Any integer

  Ex: http://mockr-hr.herokuapp.com/1/james/comments?start=20

**-size**

  Values: Any integer

  Ex: http://mockr-hr.herokuapp.com/1/james/comments?size=10

**combination**

  Ex: http://mockr-hr.herokuapp.com/1/james/comments?createdAt=ASC&start=10&size=20

-Get specific object: GET http://mockr-hr.herokuapp.com/1/:username/:route?id=:id

Insert the id of the object you want to get as a url parameter

Ex: http://mockr-hr.herokuapp.com/1/james/comments?id=1

-Post new data: POST http://mockr-hr.herokuapp.com/1/:username/:route

Pass the object you want to create in the request body 

Ex: http://mockr-hr.herokuapp.com/1/james/comments

-Edit data: PUT http://mockr-hr.herokuapp.com/1/:username/:route?id=:id

Insert the id of the object you want to change as a url parameter 

Pass the new data of the object in the request body

Ex: http://mockr-hr.herokuapp.com/1/james/comments?id=3

-Delete data: DELETE http://mockr-hr.herokuapp.com/1/:username/:route?id=:id

Insert the id of the object you want to delete as a url parameter

Ex: http://mockr-hr.herokuapp.com/1/james/comments?id=3

How to add business logic

The business logic you insert will be run when you do a POST request to the API endpoint you create in Mockr. You can access all the keys you passed in the request body. You can also access 'res' to end the response. You only can use pure Javascript.

Ex: If you do a POST to http://mockr.co/1/james/comments and pass {username: 'James', msg: 'Hi'}, you will have access to 'username' and 'msg' inside the business logic.

Ex Business Logic: '(function() {msg = msg.upperCase(); }()'

Ex Business Logic: '(function() {res = 'end response with a 500'}()'