All Projects → cryptlex → Rest Api Response Format

cryptlex / Rest Api Response Format

Licence: mit
REST API response format using HTTP status codes

Projects that are alternatives of or similar to Rest Api Response Format

Jaguar
Jaguar, a server framework built for speed, simplicity and extensible. ORM, Session, Authentication & Authorization, OAuth
Stars: ✭ 286 (-19.66%)
Mutual labels:  rest-api, rest, restful
Http Fake Backend
Build a fake backend by providing the content of JSON files or JavaScript objects through configurable routes.
Stars: ✭ 253 (-28.93%)
Mutual labels:  rest-api, rest, restful
Restfm
RESTful web services for FileMaker server.
Stars: ✭ 76 (-78.65%)
Mutual labels:  rest-api, rest, restful
Generator Http Fake Backend
Yeoman generator for building a fake backend by providing the content of JSON files or JavaScript objects through configurable routes.
Stars: ✭ 49 (-86.24%)
Mutual labels:  rest-api, rest, restful
Node Express Mongoose Passport Jwt Rest Api Auth
Node, express, mongoose, passport and JWT REST API authentication example
Stars: ✭ 146 (-58.99%)
Mutual labels:  rest-api, rest, restful
Calm
It is always Calm before a Tornado!
Stars: ✭ 50 (-85.96%)
Mutual labels:  rest-api, rest, restful
Node Typescript Mongodb
node js typescript mongodb express generator yo
Stars: ✭ 96 (-73.03%)
Mutual labels:  rest-api, rest, restful
Apidoc
RESTful API 文档生成工具,支持 Go、Java、Swift、JavaScript、Rust、PHP、Python、Typescript、Kotlin 和 Ruby 等大部分语言。
Stars: ✭ 785 (+120.51%)
Mutual labels:  rest-api, rest, restful
Codeigniter Jwt Sample
CodeIgniter JWT Sample
Stars: ✭ 144 (-59.55%)
Mutual labels:  rest-api, rest, restful
Ssm
👅基于RESTful风格的前后端分离的SSM框架,集成了shiro和swagger等框架
Stars: ✭ 141 (-60.39%)
Mutual labels:  rest-api, rest, restful
Farwest
Framework for building RESTful HATEOAS-driven applications.
Stars: ✭ 18 (-94.94%)
Mutual labels:  rest-api, rest, restful
Graphql2rest
GraphQL to REST converter: automatically generate a RESTful API from your existing GraphQL API
Stars: ✭ 181 (-49.16%)
Mutual labels:  rest-api, rest, restful
Gen
Converts a database into gorm structs and RESTful api
Stars: ✭ 825 (+131.74%)
Mutual labels:  rest-api, rest, restful
Api Strategy
Equinor API Strategy
Stars: ✭ 56 (-84.27%)
Mutual labels:  rest-api, rest, restful
Ngx Restangular
Restangular for Angular 2 and higher versions
Stars: ✭ 787 (+121.07%)
Mutual labels:  rest-api, rest, restful
Http restful api
整理HTTP后台端的RESTful API方面的知识
Stars: ✭ 94 (-73.6%)
Mutual labels:  rest-api, rest, restful
Restful Api Design References
RESTful API 设计参考文献列表,可帮助你更加彻底的了解REST风格的接口设计。
Stars: ✭ 4,830 (+1256.74%)
Mutual labels:  rest-api, rest, restful
Rest Api Design Guide
NBB's REST-ish API Design Guide
Stars: ✭ 643 (+80.62%)
Mutual labels:  rest-api, rest, restful
Watsonwebserver
Watson is the fastest, easiest way to build scalable RESTful web servers and services in C#.
Stars: ✭ 125 (-64.89%)
Mutual labels:  rest-api, rest, restful
Koa Restful Boilerplate
Koa 2 RESTful API boilerplate
Stars: ✭ 146 (-58.99%)
Mutual labels:  rest-api, rest, restful

rest-api-response-format

REST API response format based on some of the best practices

The swagger.yaml file for following sample responses is available at:

https://github.com/adnan-kamili/swagger-sample-template

Rest API Popular Endpoint Formats

https://api.example.com/v1/items

https://example.com/api/v1/items

Rest API Success Responses

1- GET - Get single item - HTTP Response Code: 200

    HTTP/1.1 200
    Content-Type: application/json

    {
        "id": 10,
        "name": "shirt",
        "color": "red",
        "price": "$23"
    }

2- GET - Get item list - HTTP Response Code: 200

    HTTP/1.1 200
    Pagination-Count: 100
    Pagination-Page: 5
    Pagination-Limit: 20
    Content-Type: application/json
    
    [
      {
        "id": 10,
        "name": "shirt",
        "color": "red",
        "price": "$123"
      },
      {
        "id": 11,
        "name": "coat",
        "color": "black",
        "price": "$2300"
      }
    ]

3- POST - Create a new item - HTTP Response Code: 201

    HTTP/1.1  201
    Location: /v1/items/12
    Content-Type: application/json
 
    {
      "message": "The item was created successfully"
    }

4- PATCH - Update an item - HTTP Response Code: 200/204

If updated entity is to be sent after the update

    HTTP/1.1  200
    Content-Type: application/json
 
    {
        "id": 10,
        "name": "shirt",
        "color": "red",
        "price": "$23"
    }

If updated entity is not to be sent after the update

    HTTP/1.1  204

5- DELETE - Delete an item - HTTP Response Code: 204

    HTTP/1.1  204

Rest API Error Responses

1- GET - HTTP Response Code: 404

    HTTP/1.1  404
    Content-Type: application/json
 
    {
      "message": "The item does not exist"
    }

2- DELETE - HTTP Response Code: 404

    HTTP/1.1  404
    Content-Type: application/json
 
    {
      "message": "The item does not exist"
    }

3- POST - HTTP Response Code: 400

    HTTP/1.1  400
    Content-Type: application/json
    
    {
        "message": "Validation errors in your request", /* skip or optional error message */
        "errors": [
            {
                "message": "Oops! The value is invalid",
                "code": 34,
                "field": "email"
            },
            {
                "message": "Oops! The format is not correct",
                "code": 35,
                "field": "phoneNumber"
            }
        ]
    }

4- PATCH - HTTP Response Code: 400/404

    HTTP/1.1  400
    Content-Type: application/json
    
    {
        "message": "Validation errors in your request", /* skip or optional error message */
        "errors": [
            {
                "message": "Oops! The format is not correct",
                "code": 35,
                "field": "phoneNumber"
            }
        ]
    }
    
    
    HTTP/1.1  404
    Content-Type: application/json
 
    {
      "message": "The item does not exist"
    }

5- VERB Unauthorized - HTTP Response Code: 401

    HTTP/1.1  401
    Content-Type: application/json
 
    {
      "message": "Authentication credentials were missing or incorrect"
    }

6- VERB Forbidden - HTTP Response Code: 403

    HTTP/1.1  403
    Content-Type: application/json
 
    {
      "message": "The request is understood, but it has been refused or access is not allowed"
    }

7- VERB Conflict - HTTP Response Code: 409

    HTTP/1.1  409
    Content-Type: application/json
 
    {
      "message": "Any message which should help the user to resolve the conflict"
    }

8- VERB Too Many Requests - HTTP Response Code: 429

    HTTP/1.1  429
    Content-Type: application/json
 
    {
      "message": "The request cannot be served due to the rate limit having been exhausted for the resource"
    }

9- VERB Internal Server Error - HTTP Response Code: 500

    HTTP/1.1  500
    Content-Type: application/json
 
    {
      "message": "Something is broken"
    }

10- VERB Service Unavailable - HTTP Response Code: 503

    HTTP/1.1  503
    Content-Type: application/json
 
    {
      "message": "The server is up, but overloaded with requests. Try again later!"
    }

Validation Error Formats

Validation error formats can be different depending on your requirements. Following are some other popular formats, other than the one used above.

    HTTP/1.1  400
    Content-Type: application/json
    
    {
        "message": "Validation errors in your request", /* skip or optional error message */
        "errors": {
            "email": [
                  "Oops! The email is invalid"
                ],
            "phoneNumber": [
                  "Oops! The phone number format is not correct"
                ]
        }
    }
    HTTP/1.1  400
    Content-Type: application/json
    
    {
        "message": "Validation errors in your request", /* skip or optional error message */
        "errors": {
            "email": [
              {
                "message": "Oops! The email is invalid",
                "code": 35
              }
            ],
            "phoneNumber": [
              {
                "message": "Oops! The phone number format is not correct",
                "code": 36
              }
            ]
        }
    }

References

PATCH with partial json can be used for updating the resource: https://tools.ietf.org/html/rfc7396

Avoid using 'X-' in custom headers: https://tools.ietf.org/html/rfc6648

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].