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 |
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
$ npm install --global @stoplight/prism-cli
[...]
$ prism --help
Start the mock server
$ prism mock -p 8080 ./openapi.yml
[CLI] ... awaiting Starting Prism...
Validate from another console
$ curl http://localhost:8080/jobs
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
$ curl -v http://www.example.com/
$ curl -o out.json http://www.example.com/index.html
$ curl -d 'id=9&name=baeldung' http://localhost:8082/spring-rest/foos/new
$ curl -d @request.json -H "Content-Type: application/json" http://localhost:8082/spring-rest/foos/new
$ curl -d '{"id":9,"name":"baeldung"}' -H 'Content-Type: application/json' http://localhost:8082/spring-rest/foos/new
$ curl -d @request.json -H 'Content-Type: application/json' -X PUT http://localhost:8082/spring-rest/foos/9
$ curl -X DELETE http://localhost:8082/spring-rest/foos/9
$ curl --user baeldung:secretPassword http://example.com/
HTTP request on TCP connection
OS: Linux
Commands: telnet
, openssl
Tested: ubuntu
Last updated