ApiServer 0.0.1 documentation

1. API specification

«  Sample of REST API Server with multi-language   ::   Contents   ::   2. Middlewares  »

1. API specification

1.1. Response

All responses are returned in JSON. But some internal errors are responded when HTTP header ‘Accept’ contains ‘text/html’ and the server runs in debug mode.

JSON Response

All responses are returned in the same format.

{
  "response_code": HTTP_RESPONSE_CODE,
  "message": ERROR_MESSAGE,
  "more_info": ERROR_DETAIL_URL,
  "code": ERROR_CODE
  "body": RESPONSE_BODY
}
Data:
  • HTTP_RESPONSE_CODE (string) – HTTP Response code. Exists only when a parameter ‘supress_response_codes’ is true. NOTE: not number, string.
  • ERROR_MESSAGE (string) – Error message. The message are written in the language specified by HTTP request header ‘Accept-Language’.
  • ERROR_DETAIL_URL (string) – URL for more details about the error.
  • ERROR_CODE (string) – Error code on the application domain.
  • RESPONSE_BODY (Object) – Response body.
Error stacktrace

Error stack trace written in HTML.

Single user response

Response body for a single user is below.

{
  "id": USER_ID,
  "name": USER_NAME
}
Data:
  • USER_ID (integer) – id number for user
  • USER_NAME (string) – name of user
Multiple user response

Response body for multiple users is below.

[
  ['id', 'name'],
  [USER_ID_1, USER_NAME_1],
  ...
]
Data:
  • USER_ID_1 (integer) – id number for the first user
  • USER_NAME_1 (string) – name of the first user

1.2. users

POST /v1/users[.json]?name&supress_response_codes
Query params:

name (string) – new user name

Opt. params:

supress_response_codes (boolean) – returns response with code 200 always. The response code is in the response body.

Responses:
  • 200 – create successfully.
  • 400 – required parameters not exists.
GET /v1/users[.json]?fields&orderby&offset&limit&method&supress_response_codes
Opt. params:
  • fields (string) – columns contained in response
  • orderby (string) – sort key
  • offset (integer) – pager offset
  • limit (integer) – pager limit
  • method (string) – if ‘post’, API Users POST. if ‘delete’, API Users DELETE.
  • supress_response_codes (boolean) – returns response with code 200 always. The response code is in the response body.
Responses:

200 – list successfully.

DELETE /v1/users[.json]?supress_response_codes
Opt. params:supress_response_codes (boolean) – returns response with code 200 always. The response code is in the response body.
Responses:200 – delete all users successfully.
GET /v1/users/{user_id}[.json]?method&supress_response_codes

Show the user.

Opt. params:
  • user_id (integer) – user_id
  • method (string) – if ‘put’, API User PUT. if ‘delete’, API User DELETE.
  • supress_response_codes (boolean) – returns response with code 200 always. The response code is in the response body.
Responses:
  • 200 – list successfully.
  • 404 – no user found.
PUT /v1/users/{user_id}[.json]?name&supress_response_codes

If exists update the user. If not error.

Opt. params:
  • user_id (integer) – user_id
  • name (string) – user name
  • supress_response_codes (boolean) – returns response with code 200 always. The response code is in the response body.
Responses:
  • 200 – list successfully.
  • 404 – no user found.
DELETE /v1/users/{user_id}[.json]?supress_response_codes

Delete the user.

Opt. params:
  • user_id (integer) – user_id
  • supress_response_codes (boolean) – returns response with code 200 always. The response code is in the response body.
Responses:
  • 200 – list successfully.
  • 404 – no user found.
GET /v1/users/count[.json]?supress_response_codes

Returns user count.

Opt. params:supress_response_codes (boolean) – returns response with code 200 always. The response code is in the response body.
Responses:200 – count successfully.

Table Of Contents

Previous topic

Sample of REST API Server with multi-language

Next topic

2. Middlewares

This Page

«  Sample of REST API Server with multi-language   ::   Contents   ::   2. Middlewares  »