Skip to content

Instantly share code, notes, and snippets.

@Ranur-react
Forked from simonwep/APIDocExample.md
Created February 1, 2023 06:45

Revisions

  1. @simonwep simonwep revised this gist Feb 14, 2018. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions APIDocExample.md
    Original file line number Diff line number Diff line change
    @@ -7,9 +7,9 @@ This API uses `POST` request to communicate and HTTP [response codes](https://en
    200: Success
    400: Bad request
    401: Unauthorized
    402: Request failed
    404: Cannot be found
    405: Method not allowed
    422: Unprocessable Entity
    50X: Server Error
    ```
    ### Error Codes Details
    @@ -19,7 +19,8 @@ This API uses `POST` request to communicate and HTTP [response codes](https://en
    120: User Authenticaion Invalid
    130: Parameter Error
    140: Item Missing
    150: Server Error
    150: Conflict
    160: Server Error
    ```
    ### Example Error Message
    ```json
  2. @simonwep simonwep created this gist Feb 13, 2018.
    74 changes: 74 additions & 0 deletions APIDocExample.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,74 @@
    # API Documentation Example
    This API uses `POST` request to communicate and HTTP [response codes](https://en.wikipedia.org/wiki/List_of_HTTP_status_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
    402: Request failed
    404: Cannot be found
    405: Method not allowed
    50X: Server Error
    ```
    ### Error Codes Details
    ```
    100: Bad Request
    110: Unauthorized
    120: User Authenticaion Invalid
    130: Parameter Error
    140: Item Missing
    150: Server Error
    ```
    ### Example Error Message
    ```json
    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:**
    ```json
    POST /login HTTP/1.1
    Accept: application/json
    Content-Type: application/json
    Content-Length: xy

    {
    "username": "foo",
    "password": "1234567"
    }
    ```
    **Successful Response:**
    ```json
    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:**
    ```json
    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."
    }
    ```