APIs ~ Introduction - rohit120582sharma/Documentation GitHub Wiki

API stands for Application Programming Interface.

An application contains multiple programs whereas a program contains code and perform a certain task. An interface is a way for an external party to interact with a program. A programming interface is an interface that allows other programs to use the functionality of the program.

An API is responsible for creating this communication interface. It is a program that makes this communication possible. It is a building block that works behind the scenes to connect different applications and systems so they can share information.

At a high level, APIs are ways for one piece of code to talk to another piece of code.

APIs are entry points into your organization's capabilities that can be accessed through different channels such as browsers, mobile apps, social networks, and IoT devices.


API styles and standards:

  • Tunnel Style (SOAP : Simple Object Access Protocol)
  • URI Style (CRUD : Create, Read, Update, and Delete)
    • Focus on the Objects/Entities
    • Design public identifiers (URIs) - http://{server}/{object}/{id}
    • Use HTTP methods as operations on Entities
    • Clients use URIs to pass objects
  • Hypermedia Style (REST : Representational State Transfer)
    • Exposes a task-based interface, often incorporating a workflow or state machine
    • Focus on the Tasks/Use cases
  • Event-Driven Style (Reactive)
    • Includes the WebSocket protocol, which transmits data between a client and server with a low overhead.
  • GraphQL
    • GraphQL allows client users to tell the API exactly how to present the retrieved data without needing to create a large collection of unnecessary requests or responses.
  • gRPC
    • A language-agnostic and emphasizes ‘contract-first’ approach to API development, which requires client and server to agree on the payload format but allows for performance at scale.


REST

REST API stands for Representational State Transfer APIs and it is resource-based where computers(client-server code) communicate over a network and usually over the internet using HTTP or over another protocol like FTP.

An API in the context of Express is a web service that accepts requests and returns structured data (JSON in many cases). The fundamentals of an Express API are pretty straightforward: take a request, parse it, and respond with a JSON object and an HTTP status code. You’ll use middleware and route to take requests and parse them, and you’ll use Express’s conveniences to respond to requests.

There’s a common application pattern: create, read, update, and delete. It’s shortened to CRUD.

HTTP methods or HTTP verbs tell a server to take appropriate action on the resources. HTTP methods and how they relate to common application actions.

  • GET typically corresponds to reading resources.
  • POST typically corresponds to creating resources
  • PUT/PATCH typically corresponds to changing resources
  • DELETE typically corresponds to removing resources

Versioning your API is helpful for compatibility. Express’s router feature helps you create different versions of your API.

There are lots of HTTP status codes (code 404 is perhaps the most famous). A good API uses these status codes properly. Express adds a method called status to the HTTP response object.


⚠️ **GitHub.com Fallback** ⚠️