This is an application written in Python and using Flask framework showcasing a standard implementation of RESTful APIs.
- Python 2.7
- Flask
- SqlAlchemy
This section will cover how to setup and run the application locally on any type of desktop
In order to setup and run the code locally below steps shall be required:
-
Install Python 2.7 as the runtime engine.
-
Install Flask framework using
pip
provided by Python 2.7 to euip app with a web-server :pip install flask
-
Install Http Auth library from Flask for use of implementing Basic_Auth :
pip install flask_httpauth
-
Install SqlAlchemy for RDBMS purpose :
pip install sqlalchemy
-
Install
httplib2
library to provide support for http operations as client :pip install httplib2
Use any Python IDE of your choice. PyCharm Community Edition can be used for free.
Launching the app is simple. Just run the main.py
program to start the application. The Python command line or the chosen IDE can be used to do the same.
If started successfully, the log entry like the one below should be made on the console:
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
That indicates that the application is started successfully on localhost port 5000
To consume the APIs hosted by the application can be accessed using the documentation as below.
Please note that for any required authentication and authorization
BASIC_AUTH
is the only available mechanism at the moment, that takes the registered users' credentials to authenticate.
Below is the list of operations available, and the API endpoints and corresponding HTTP Methods to complete the operation.
API : /api/v1/users
HTTP Method : POST
Security : None
Request Body :
{
"UserDetails": [{
"name": "Ashwin", <STRING, MANDATORY>
"email": "ashwin.gupta@abc.com", <STRING, MANDATORY>
"password": "password" <STRING, MANDATORY>
}]
}
Response :
- HTTP Status : UNAUTHORIZED - 401 (for case of authN failure)
- HTTP Status : OK - 200 (For all rest cases)
- Body :
{
"ResponseMessage": [{
"responseCode": "api response code",
"responseMessage": "message text"
}]
}
- HTTP Status : INTERNAL_SERVER_ERROR - 500 (for any other error)
API : /api/v1/users
HTTP Method : GET
Security : BASIC_AUTH
Request Body : None
Response :
success
- HTTP Status : OK - 200 (For all rest cases)
- Body :
{
"UserDetails": [{
"email": "ashwin.gupta@abc.com",
"id": 1,
"name": "Ashwin"
}, {
"email": "rishi.madan@abc.com",
"id": 2,
"name": "Rishi"
}]
}
failure
- HTTP Status : UNAUTHORIZED - 401 (for case of authN failure)
- HTTP Status : OK - 200 (For all rest cases)
- Body :
{
"ResponseMessage": [{
"responseCode": "api response code",
"responseMessage": "message text"
}]
}
- HTTP Status : INTERNAL_SERVER_ERROR - 500 (for any other error)
API : /api/v1/users/<int:id>
HTTP Method : GET
Security : BASIC_AUTH
Request Body : None
Response :
success
- HTTP Status : OK - 200 (For all rest cases)
- Body :
{
"UserDetails": [{
"email": "ashwin.gupta@abc.com",
"id": 1,
"name": "Ashwin"
}]
}
failure
- HTTP Status : UNAUTHORIZED - 401 (for case of authN failure)
- HTTP Status : OK - 200 (For all rest cases)
- Body :
{
"ResponseMessage": [{
"responseCode": "api response code",
"responseMessage": "message text"
}]
}
- HTTP Status : INTERNAL_SERVER_ERROR - 500 (for any other error)
API : /api/v1/users/<int:id>
HTTP Method : PUT
Security : BASIC_AUTH
Request Body :
{
"UserDetails": [{
"newpassword": "newpassword" <STRING, MANDATORY>
}]
}
Response :
- HTTP Status : UNAUTHORIZED - 401 (for case of authN failure)
- HTTP Status : OK - 200 (For all rest cases)
- Body :
{
"ResponseMessage": [{
"responseCode": "api response code",
"responseMessage": "message text"
}]
}
- HTTP Status : INTERNAL_SERVER_ERROR - 500 (for any other error)
API : /api/v1/users/<int:id>
HTTP Method : DELETE
Security : BASIC_AUTH
Request Body : None
Response :
- HTTP Status : UNAUTHORIZED - 401 (for case of authN failure)
- HTTP Status : OK - 200 (For all rest cases)
- Body :
{
"ResponseMessage": [{
"responseCode": "api response code",
"responseMessage": "message text"
}]
}
#### Requests Creation
**API** : `/api/v1/requests`
**HTTP Method** : POST
**Security** : BASIC_AUTH
**Request Body** :
```json
{
"requestDetails": [{
"meanType": "Italian", <STRING, MANDATORY>
"mealTime: "Dinner", <STRING, MANDATORY>
"location": "Lag Vegas, Naveda" <STRING, MANDATORY>
}]
}
Response :
- HTTP Status : UNAUTHORIZED - 401 (for case of authN failure)
- HTTP Status : OK - 200 (For all rest cases)
- Body :
{
"ResponseMessage": [{
"responseCode": "api response code",
"responseMessage": "message text"
}]
}
- HTTP Status : INTERNAL_SERVER_ERROR - 500 (for any other error)
API : /api/v1/requests
HTTP Method : GET
Security : BASIC_AUTH
Request Body : None
Response :
success
- HTTP Status : OK - 200 (For all rest cases)
- Body :
{
"requestDetails": [{
"mealType": "Italian",
"mealTime": "Dinner",
"location": "Lag Vegas, Naveda",
"id": 1,
"user_id": "2",
"filled": False
}, {
"requestDetails": [{
"mealType": "Mughlai",
"mealTime": "Lunch",
"location": "Wesminster, London",
"id": 2,
"user_id": "1",
"filled": True
}]
}
failure
- HTTP Status : UNAUTHORIZED - 401 (for case of authN failure)
- HTTP Status : OK - 200 (For all rest cases)
- Body :
{
"ResponseMessage": [{
"responseCode": "api response code",
"responseMessage": "message text"
}]
}
- HTTP Status : INTERNAL_SERVER_ERROR - 500 (for any other error)
API : /api/v1/requests/<int:id>
HTTP Method : GET
Security : BASIC_AUTH
Request Body : None
Response :
success
- HTTP Status : OK - 200 (For all rest cases)
- Body :
{
"requestDetails": [{
"requestDetails": [{
"mealType": "Mughlai",
"mealTime": "Lunch",
"location": "Wesminster, London",
"id": 2,
"user_id": "1",
"filled": True
}]
}
failure
- HTTP Status : UNAUTHORIZED - 401 (for case of authN failure)
- HTTP Status : OK - 200 (For all rest cases)
- Body :
{
"ResponseMessage": [{
"responseCode": "api response code",
"responseMessage": "message text"
}]
}
- HTTP Status : INTERNAL_SERVER_ERROR - 500 (for any other error)
API : /api/v1/requests/<int:id>
HTTP Method : PUT
Security : BASIC_AUTH
Request Body :
{
"requestDetails": [{
"meanType": "Italian", <STRING, MANDATORY>
"mealTime: "Lunch", <STRING, MANDATORY>
"location": "Lag Vegas, Naveda" <STRING, MANDATORY>
}]
}
Response :
- HTTP Status : UNAUTHORIZED - 401 (for case of authN failure)
- HTTP Status : OK - 200 (For all rest cases)
- Body :
{
"ResponseMessage": [{
"mealType": "Italian",
"mealTime": "Dinner",
"location": "Lag Vegas, Naveda",
"id": 1,
"user_id": "2",
"filled": False
}]
}
- HTTP Status : INTERNAL_SERVER_ERROR - 500 (for any other error)
API : /api/v1/requests/<int:id>
HTTP Method : DELETE
Security : BASIC_AUTH
Request Body : None
Response :
- HTTP Status : UNAUTHORIZED - 401 (for case of authN failure)
- HTTP Status : OK - 200 (For all rest cases)
- Body :
{
"ResponseMessage": [{
"responseCode": "api response code",
"responseMessage": "message text"
}]
}
- HTTP Status : INTERNAL_SERVER_ERROR - 500 (for any other error)
API : /api/v1/proposals
HTTP Method : POST
Security : BASIC_AUTH
Request Body :
{
"ProposalDetails": [{
"requestId": 5 <INT, MANDATORY>
}]
}
Response :
- HTTP Status : UNAUTHORIZED - 401 (for case of authN failure)
- HTTP Status : OK - 200 (For all rest cases)
- Body :
{
"ResponseMessage": [{
"responseCode": "api response code",
"responseMessage": "message text"
}]
}
- HTTP Status : INTERNAL_SERVER_ERROR - 500 (for any other error)
API : /api/v1/proposals
HTTP Method : GET
Security : BASIC_AUTH
Request Body : None
Response :
success
- HTTP Status : OK - 200 (For all rest cases)
- Body :
{
"ProposalDetails": [{
"filled": false,
"id": 1,
"user_proposed_to": "Jane",
"user_proposed_from": "Tarzan",
"request_id": 91
}, {
"filled": true,
"id": 1,
"user_proposed_to": "Romeo",
"user_proposed_from": "Juliet",
"request_id": 12
}]
}
failure
- HTTP Status : UNAUTHORIZED - 401 (for case of authN failure)
- HTTP Status : OK - 200 (For all rest cases)
- Body :
{
"ResponseMessage": [{
"responseCode": "api response code",
"responseMessage": "message text"
}]
}
- HTTP Status : INTERNAL_SERVER_ERROR - 500 (for any other error)
API : /api/v1/proposals
HTTP Method : GET
Security : BASIC_AUTH
Request Body : None
Response :
success
- HTTP Status : OK - 200 (For all rest cases)
- Body :
{
"ProposalDetails": [{
"filled": true,
"id": 1,
"user_proposed_to": "Romeo",
"user_proposed_from": "Juliet",
"request_id": 12
}]
}
failure
- HTTP Status : UNAUTHORIZED - 401 (for case of authN failure)
- HTTP Status : OK - 200 (For all rest cases)
- Body :
{
"ResponseMessage": [{
"responseCode": "api response code",
"responseMessage": "message text"
}]
}
- HTTP Status : INTERNAL_SERVER_ERROR - 500 (for any other error)
API : /api/v1/proposals/<int:id>
HTTP Method : PUT
Security : BASIC_AUTH
Request Body : None
Response :
- HTTP Status : UNAUTHORIZED - 401 (for case of authN failure)
- HTTP Status : OK - 200 (For all rest cases)
- Body :
{
"ResponseMessage": [{
"responseCode": "api response code",
"responseMessage": "message text"
}]
}
- HTTP Status : INTERNAL_SERVER_ERROR - 500 (for any other error)
API : /api/v1/proposals/<int:id>
HTTP Method : DELETE
Security : BASIC_AUTH
Request Body : None
Response :
- HTTP Status : UNAUTHORIZED - 401 (for case of authN failure)
- HTTP Status : OK - 200 (For all rest cases) (For all rest cases)
- Body :
{
"ResponseMessage": [{
"responseCode": "api response code",
"responseMessage": "message text"
}]
}
- HTTP Status : INTERNAL_SERVER_ERROR - 500 (for any other error)