mishelashala / sms-mexbt

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

API Contract

Index:

  1. Usage
  1. Error Handling

Usage

POST /api/messages

It creates a new verification message.

Request

headers:

Accept: application/json

body:

{
    "phone": 015555555555
    "email": "example@domain.com"
}

Response

Headers:

Content-Type: application/json
Status: 201 Created

Body:

{
    "server": {
        "status": 201,
        "message": "Created"
    },
    "client": {
        "status": 10,
        "status": "Message Sent"
    },
    "data": {
        "_id": "507f1f77bcf86cd799439011"
        "created_at": "2016-05-18T16:00:00Z"
        "verified": false,
        "phone": "015555555555",
        "email": "example@domain.com"
    }
}

POST /api/verify

It verifies a user.

Request

Headers:

Accept: application/json

Body:

{
    "email": "example@domain.com",
    "code": "abcdef" // len(6)
}

Response

Headers:

Content-Type: application/json
Status: 202 Accepted

Body:

{
    "server": {
        "status": 202,
        "message": "Accepted"
    },
    "client": {
        "status": 11,
        "message": "User Verified"
    },
    "data": {
        "_id": "507f1f77bcf86cd799439011",
        "created_at": "2016-05-18T16:00:00Z",
        "updated_at": "2016-05-18T16:01:00Z",
        "email": "starships@outlook.com",
        "phone": "015555555555",
        "code": "abcdef",
        "verified": true,
    }
}

Error Handling

Invalid User Input

If you try to submit invalid (blank or not corresponding to the model) data.

Response

Headers:

Content-Type: application/json
Status: 400 Bad Request

Body:

{
    "server": {
        "status": 400,
        "message": "Bad Request"
    },
    "client": {
        "status": 20,
        "message": "Invalid User Input"
    }
}

Email To Verify Not Found

If the user has not receive a verification mesage and is trying to "verify" his account.

Response

Headers:

Content-Type: application/json
Status: 400 Bad Request

Body:

{
    "server": {
        "status": 400,
        "message": "Bad Request"
    },
    "client": {
        "status": 23,
        "message": "User Not Found"
    }
}

Invalid Verification Code

If the verification code is wrong.

Response

Headers:

Content-Type: application/json
Status: 400 Bad Request

Body:

{
    "server": {
        "status": 400,
        "message": "Bad Request"
    },
    "client": {
        "status": 24,
        "message": "Invalid Verification Code"
    }
}

User Already Verified

If you try to verify an already verified user.

Response

Headers:

Content-Type: application/json
Status: 400 Bad Request

Body:

{
    "server": {
        "status": 400,
        "message": "Bad Request"
    },
    "client": {
        "status": 25,
        "message": "User Already Verified"
    }
}

Database Connection Failed

If something went wrong during the db connection.

Response

Headers:

Content-Type: application/json
Status: 500 Internal Server Error

Body:

{
    "server": {
        "status": 500,
        "message": "Internal Server Error"
    },
    "client": {
        "status": 31,
        "message": "Database Connection Failed"
    }
}

Cannot Auth To Alphapoint

If the service could not auth with alphapoint.

Response

Headers:

Content-Type: application/json
Status: 500 Internal Server Error

Body:

{
    "server": {
        "status": 500,
        "message": "Internal Server Error"
    },
    "client": {
        "status": 40,
        "message": "Cannot Auth To Alphapoint"
    }
}

Cannot Change Verification Level

If the service could not change the verification level of the user (alphapoint).

Response

Headers:

Content-Type: application/json
Status: 500 Internal Server Error

Body:

{
    "server": {
        "status": 500,
        "message": "Internal Server Error"
    },
    "client": {
        "status": 41,
        "message": "Cannot Change Verification Level"
    }
}

Wrong Accept Header

If the Accept header is different from application/json.

Request

Headers:

Accept: text/html

Response

Headers:

Content-Type: application/json
Status: 406 Not Acceptable

Body:

{
    "server": {
        "status": 406,
        "message": "Not Acceptable"
    }
}

Method Not Allowed

Only POST method allowed.

Response

Headers:

Content-Type: application/json
Status: 405 Method Not Allowed

Body:

{
    "server": {
        "status": 405,
        "message": "Method Not Allowed"
    }
}

Not Found

Only /api/messages and /api/verify/ routes allowed.

Response

Headers:

Content-Type: application/json
Status: 404 Not Found

Body:

{
    "server": {
        "status": 404,
        "message": "Not Found"
    }
}

About


Languages

Language:JavaScript 100.0%