API

RELATED: EXAMPLES > Cloud Solutions#API |

Public APIs

List to be sorted...

MISC

WEATHER

Examples

RELATED: EXAMPLES > Cloud Solutions#API |

chevron-rightBasic API; from json file source; graphqlhashtag

Github: https://github.com/gabepublic/api-graphql-js-file-01arrow-up-right

Summary:

  • Language(s): javascript

  • Frameworks: graphql

  • API source: json file

chevron-rightSimple 5 countries API; from json file; python flask; dockerhashtag

Github: https://github.com/gabepublic/docker-api-countries-pyflaskarrow-up-right

Summary:

  • Language(s): python flask

  • API source: json file

Source: List of Countries [GraphQL] - https://github.com/trevorblades/countriesarrow-up-right

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/arrow-up-right

  • Use the swagger editor to develop OpenAPI definitions

  • Validate the OpenAPI specifications

Mock Server

Choices:

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:

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

GraphQL

AWS

Testing

Tools

curL

HTTP request on TCP connection

OS: Linux Commands: telnet, openssl Tested: ubuntu

chevron-rightInstructionshashtag
  • 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