API
RELATED: EXAMPLES > Cloud Solutions#API |
Public APIs
List to be sorted...
MISC
Cat Fact - api: https://cat-fact.herokuapp.com | doc: https://alexwohlbruck.github.io/cat-facts/docs/ | website: https://cat-fact.herokuapp.com/#/ |
Minimal Avatars - api: https://api.minimalavatars.com | doc: https://minimalavatars.com/ |
Pirate talk - api: https://api.funtranslations.com | doc: https://funtranslations.com/api/pirate |
Random users - api: https://randomuser.me/api/?results=50 | doc: |
SF Food Trucks - api: https://data.sfgov.org/Economy-and-Community/Mobile-Food-Facility-Permit/rqzj-sfat | doc: |
SEARCH
DuckDuckGo - api: https://api.duckduckgo.com | doc: https://api.duckduckgo.com/api |
Search - https://serpapi.com/ - google search api; free 100 searches/mo.
WEATHER
OpenWeather - api: https://openweathermap.org/api | FREE: 60 calls/minute 1,000,000 calls/month | doc: |
Examples
RELATED: EXAMPLES > Cloud Solutions#API |
Basic API; from json file source; graphql
Github: https://github.com/gabepublic/api-graphql-js-file-01
Summary:
Language(s): javascript
Frameworks: graphql
API source: json file
Simple 5 countries API; from json file; python flask; docker
Github: https://github.com/gabepublic/docker-api-countries-pyflask
Summary:
Language(s): python flask
API source: json file
Source: List of Countries [GraphQL] - https://github.com/trevorblades/countries
OpenAPI definition
Excellent Reference: Designing APIs with Swagger and OpenAPI by Josh Ponelat, Lukas Rosenstock; Published by Manning Publications Web APIs
Swagger Editor
Web Editor: https://editor.swagger.io/
Use the swagger editor to develop OpenAPI definitions
Validate the OpenAPI specifications
Mock Server
Choices:
Prism is an open-source mock server that reads in an OpenAPI definition and serves up responses that fit the shape of the data; see below
ReadyAPI’s API virtualization services - https://smartbear.com/product/ready-api/
Postman mock server - www.postman.com/features/mock-api/
Setup Prism:
Prerequisite: Node.js v17+
Install
Start the mock server
Validate from another console
Implementation
Codegen
Codegen takes an OpenAPI file then generates code in various programming languages. Two types: for client, and for server. Codegen also generates documentation.
Tools:
Swagger generator (https://generator.swagger.io/); also integrated in swagger editor (https://editor.swagger.io/)
Python
Framework comparison:
Django-REST - tenure and track record as a framework that can solve a wide variety of business application problems makes it a good choice for complex, long-lived applications to be maintained by a large developer team.
Fastapi - stands out with its built-in asynchrony and an API documentation endpoint. Its maintainer-written documentation makes up quite a bit for the lack of organic documentation that comes with its younger age. Its use case is strictly APIs, and it does that one thing remarkably well.
Flask - simplicity and wealth of documentation make it an excellent choice for lightweight APIs. Especially APIs where the logic is the focus rather than the versatility of the API itself. See Example above > (Simple 5 countries API; from json file; python flask; docker)
Django-REST
Example TBD
fastapi
Go to Github: https://github.com/gabepublic/api-fastapi-py-basic
TBD - fastapi in docker and deployed to AWS ECS
TBD - fastapi docker and deployed to AWS EKS
FastAPI automatically generates an OpenAPI schema that can be accessed by your API’s users. The documentation generated by the OpenAPI schema helps users learn about your API’s features. [Source: How to Document a FastAPI App with OpenAPI]
For more detailed guidelines on how to customize documentation of fastapi, go to How to Document a FastAPI App with OpenAPI
GraphQL
GraphQL using Apollo Server (see tutorial https://www.youtube.com/watch?v=yqWzCV0kU_c); Initial reference but stop half way through for other better reference;
Apollo server website https://www.apollographql.com/docs/apollo-server/)
Deploying Apollo Server with AWS Lambda - https://www.apollographql.com/docs/apollo-server/deployment/lambda/
Learn GraphQL in 4 Hours - From Beginner to Expert - https://www.youtube.com/watch?v=yqWzCV0kU_c&t=3056s Initial reference but stop half way through for other better reference
TutorialPoint contains comprehensive & free graphql content; Use
notrealdba"fake" database for Node.js that stores data in local JSON ; read other sectionfiles,https://www.tutorialspoint.com/graphql/graphql_environment_setup.htmhttps://www.tutorialspoint.com/graphql/graphql_apollo_client.htm; very comprehensive example; study carefully
AWS
AWS API Gateway to Lambda Tutorial in Python | Build a HTTP API (2/2); youtube: https://www.youtube.com/watch?v=M91vXdjve7A
[Python] Build a CRUD Serverless API with AWS Lambda, API Gateway and a DynamoDB from Scratch; youtube: https://www.youtube.com/watch?v=9eHh946qTIk&list=PLVLP4csKTwDYuaPo83MABH-VQY9xp1Gc4&index=4&t=13s
API Authentication via API Keys | AWS API Gateway; youtube: https://www.youtube.com/watch?v=V-ac_ZvdAW4
AWS Building Modern APIs with GraphQL - https://www.youtube.com/watch?v=bRnu7xvU1_Y
Testing
Tools
Postman
curl
Swagger UI - https://swagger.io/tools/swagger-ui/
Http request on TCP connection (see below)
curL
curL; source: https://www.baeldung.com/curl-rest
HTTP request on TCP connection
OS: Linux
Commands: telnet, openssl
Tested: ubuntu
Instructions
Open a TCP connection (http or https)
Send GET /v1/reviews over TCP
❶ This is the status line, which includes the method, URI, and version of HTTP protocol. ❷ The host header is important because a lot of servers host multiple sites and use the host header to determine which site you are asking for. ❸ A blank line separates the headers from the body section.
Example of openssl connection with a response
❶ The openssl command to open up the connection ❷ Some connection details (not typed) ❸ Typing out the HTTP request ❹ The start of the response (not typed) ❺ The response body (not typed)
POST over TCP
❶ Use the POST method. ❷ Indicate the size of the body (we counted it for you). ❸ Specify the media type of the payload. ❹ Add a blank line to separate the header section from the body. ❺ Enter the body (all 37 characters in this example).
As soon as you hit that last, you should get a response. Note: if you increase the Content-Length to a larger value, your response will only be returned after you press Enter multiple times.
Last updated