PANORAMIC VIEW OF WEB API - Karen Immanuel
WHAT IS AN API?
Application Programming Interface
It provides the conventions to interact with applications without knowing the internal
logic of the code
Examples:
BUILD AN API FOR YOUR CODE
Source : Google images
REQUEST PARAMETERS OF API
URL Request parameters
https://forkify-api.herokuapp.com/api/search?q=pizza
Authorization:
- No auth
- Password based
- API Key based
- Token based
Http verb:
- GET
- POST
- PUT
- DELETE
RESPONSE PARAMETERS OF API
Source : Google images
REST API
Create (SQL INSERT) : POST – Create a resource
Read (SQL SELECT) : GET - Retrieve a representation of a resource
Update (SQL UPDATE) : PUT - Update a resource using a full representation
Delete (SQL DELETE) : DELETE - Delete a resource.
C
R
U
D
• Based on seven principles
• Representation of Resources -> URL
Example:
http://example.com/api/books
• Basic operations on resources - CRUD
EXAMPLE
Sample Data source
❑JSON data
❑Can also be from DB
FLASK IMPLEMENTATION
API TO PERFORM BASIC CRUD OPERATIONS
API TO PERFORM BASIC CRUD OPERATIONS
API TO PERFORM BASIC CRUD OPERATIONS
API TO PERFORM BASIC CRUD OPERATIONS
FLASK-RESTFUL
TEMPLATE
LONG RUNNING TASKS
Example – Sending an email
It can block the API.
LONG RUNNING TASKS
– BACKGROUND TASKS
▪Need non-blocking
request/responses
▪Task Queue – Celery
Source : Google images
THREADING VS. TASK QUEUE
1. Task queues have distributed architecture
2. Scales application extremely well
3. Add more workers according to load
4. Does not block the API
STATUS OF
BACKGROUND TASK
Client will know that background
task started.
Update status in non blocking way
➢Polling
➢Web socket
➢Server sent events
Source : Google images
API DOCUMENTATION WITH SWAGGER TOOL
oGood documentation is essential for APIs
oTake care of versioning and backward compatibility
<code snippet of swagger plugin in flask>
Output of a well- organized API doc
Source : Google images
SERVERLESS DEPLOYMENT WITH ZAPPA
While developing, APIs run on local server
For your APIs to be accessed by clients/3rd party users, they must be in a server.
Instead of dedicated server, we can go serverless
For personal projects or quick testing we can go with the option of serverless
deployment.
Easy to setup
 Demo/screenshot of serverless deployment with Zappa

Panoramic view of web APIs

  • 1.
    PANORAMIC VIEW OFWEB API - Karen Immanuel
  • 2.
    WHAT IS ANAPI? Application Programming Interface It provides the conventions to interact with applications without knowing the internal logic of the code Examples:
  • 3.
    BUILD AN APIFOR YOUR CODE Source : Google images
  • 4.
    REQUEST PARAMETERS OFAPI URL Request parameters https://forkify-api.herokuapp.com/api/search?q=pizza Authorization: - No auth - Password based - API Key based - Token based Http verb: - GET - POST - PUT - DELETE
  • 5.
    RESPONSE PARAMETERS OFAPI Source : Google images
  • 6.
    REST API Create (SQLINSERT) : POST – Create a resource Read (SQL SELECT) : GET - Retrieve a representation of a resource Update (SQL UPDATE) : PUT - Update a resource using a full representation Delete (SQL DELETE) : DELETE - Delete a resource. C R U D • Based on seven principles • Representation of Resources -> URL Example: http://example.com/api/books • Basic operations on resources - CRUD
  • 7.
    EXAMPLE Sample Data source ❑JSONdata ❑Can also be from DB FLASK IMPLEMENTATION
  • 8.
    API TO PERFORMBASIC CRUD OPERATIONS
  • 9.
    API TO PERFORMBASIC CRUD OPERATIONS
  • 10.
    API TO PERFORMBASIC CRUD OPERATIONS
  • 11.
    API TO PERFORMBASIC CRUD OPERATIONS
  • 12.
  • 13.
    LONG RUNNING TASKS Example– Sending an email It can block the API.
  • 14.
    LONG RUNNING TASKS –BACKGROUND TASKS ▪Need non-blocking request/responses ▪Task Queue – Celery Source : Google images
  • 15.
    THREADING VS. TASKQUEUE 1. Task queues have distributed architecture 2. Scales application extremely well 3. Add more workers according to load 4. Does not block the API
  • 16.
    STATUS OF BACKGROUND TASK Clientwill know that background task started. Update status in non blocking way ➢Polling ➢Web socket ➢Server sent events Source : Google images
  • 17.
    API DOCUMENTATION WITHSWAGGER TOOL oGood documentation is essential for APIs oTake care of versioning and backward compatibility <code snippet of swagger plugin in flask> Output of a well- organized API doc Source : Google images
  • 18.
    SERVERLESS DEPLOYMENT WITHZAPPA While developing, APIs run on local server For your APIs to be accessed by clients/3rd party users, they must be in a server. Instead of dedicated server, we can go serverless For personal projects or quick testing we can go with the option of serverless deployment. Easy to setup  Demo/screenshot of serverless deployment with Zappa