Skip to content

Instantly share code, notes, and snippets.

@mahfuz10
Forked from simonwep/APIDocExample.md
Created July 17, 2020 03:42
Show Gist options
  • Save mahfuz10/1aa4d737124225f60d16509eeeed9e52 to your computer and use it in GitHub Desktop.
Save mahfuz10/1aa4d737124225f60d16509eeeed9e52 to your computer and use it in GitHub Desktop.
An API-Documentation example README

API Documentation Example

This API uses POST request to communicate and HTTP response codes to indenticate status and errors. All responses come in standard JSON. All requests must include a content-type of application/json and the body must be valid JSON.

Response Codes

Response Codes

200: Success
400: Bad request
401: Unauthorized
404: Cannot be found
405: Method not allowed
422: Unprocessable Entity 
50X: Server Error

Error Codes Details

100: Bad Request
110: Unauthorized
120: User Authenticaion Invalid
130: Parameter Error
140: Item Missing
150: Conflict
160: Server Error

Example Error Message

http code 402
{
    "code": 120,
    "message": "invalid crendetials",
    "resolve": "The username or password is not correct."
}

Login

You send: Your login credentials. You get: An API-Token with wich you can make further actions.

Request:

POST /login HTTP/1.1
Accept: application/json
Content-Type: application/json
Content-Length: xy

{
    "username": "foo",
    "password": "1234567" 
}

Successful Response:

HTTP/1.1 200 OK
Server: My RESTful API
Content-Type: application/json
Content-Length: xy

{
   "apitoken": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
   "expirationDate": "2018-02-13T15:31:55.559Z"
}

Failed Response:

HTTP/1.1 401 Unauthorized
Server: My RESTful API
Content-Type: application/json
Content-Length: xy

{
    "code": 120,
    "message": "invalid crendetials",
    "resolve": "The username or password is not correct."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment