Flask RESTFUL API
This is a RESTFUL API project using Flask server.
Technology and Features :
* RESTFUL API created on Flask server.
* python-flask as backEnd.
* python-SQLAlchemy as database Interface.
* data output is on json format.
Development
HTTP GET - a Random Cafe
- Scenario : Client would need to fetch a random cafe from our API.
- Create a
/random
route in main.py
that allows GET
requests to be made to it.
- When
client
makes a GET
request to the /random
route, our Flask server should fetch a random cafe
from our database. Retun the random cafe
in JSON
format.
HTTP GET - All the Cafes
- Scenario : Client would need to fetch all cafes from our API.
- Create another
GET
route that's called /all
.
- When a
GET
request is made to this /all
route, the server should return all the cafes
from database as a JSON
format.
HTTP GET - Find a Cafe
- Scenario : Cliend would need to find cafe(s) on specific location from our API.
- Create a
/search
route to search for cafes at a particular location
.
- Client will make a
GET
request to /search
route and pass the location
as a parameter
.
- If the location the user passed as the parameter doesn't exist, server will send error message :
"Not Found": "Sorry a cafe with that id was not found in the database."
.
HTTP POST - A New Cafe
- Scenario : Cliend would need to register a new cafe to database.
- Create a
/add_cafe
route to register a new cafe
to database
.
- Use SQLAlchemy
add
function to add new row to cafes
database.
- Send
success
or failed
message with HTTP response as return.
HTTP PATCH - A Cafe's Coffee Price
- Scenario : Client would need to update a coffe price at specific cafe.
-
GET
the cafe's'id
which client would to update.
- Create a
PATCH
request route in main.py
to handle PATCH
requests to our API
.
- Send
success
or failed
message with HTTP response as return.
HTTP DELETE - A Cafe that's Closed
- Scenario : Client would neet to delete a cafe from database.
-
GET
the cafe's'id
which client would to update, also GET
special token as user's authorization
.
- Create a
DELETE
request on main.py, and send success or failed message as return.