API

fellowship

Know All About APIs

Sep 9, 2024

Any software has a frontend(user Interface) and a backend(server). API is like a middleman that gets information or performs a function. API is all around us. For example, we use APIs to get current weather data in weather apps, to get locations in google maps and in payment gateways.

What is an API?

API or Application Programming Interface is like a set of instructions that lets two computers communicate with each other. There are two types of APIs -

SOAP APIs

REST APIs

Simple Object Access Protocol APIs are slow and heavier. It uses SOAP protocol. Not commonly used now.

Representational State Transfer APIs is more simple, faster and lightweight than SOAP and can handle a wide range of use cases. It uses HTTP protocol. This is commonly used in web services.

An API consists of the following:

  1. Method: An API method defines the kind of method request and method response. Some of the methods are GET, POST, PATCH, PUT, and DELETE.

  2. Endpoint: It is the touchpoint where the API and the client connect and communicate.

  3. Path: The path of an API refers to the specific location or resource within the API that a client is trying to access or manipulate.

  4. Parameter: API parameters are additional information or options that a client can include in their request to the API, to specify or filter the desired information or action.

  5. Body: A request body is data sent by the client to your API. A response body is data your API sends to the client.

  6. Status codes: For example 200->OK, 404->Pade Not Found.

    1xx

    Communicates transfer protocol-level information.

    2xx

    Indicates that the client’s request was accepted successfully

    3xx

    Indicates that the client must take some additional action in order to complete their request.

    4xx

    This category of error status codes points the finger at clients.

    5xx

    The server takes responsibility for these error status codes.

    API Methods

    GET


    Retrieve information about the REST API resource

    POST

    Create REST API resource

    PATCH

    partially delete a part of the REST API resource

    PUT

    update a REST API resource

    DELETE

    Delete REST API resource

API Security

  • HTTPS provides an authenticated and encrypted connection between the server and client. Know more about HTTP & HTTPS

  • Always hash all passwords.

  • Never expose the API key in URL which includes username, password, pin etc.

  • OAuth(Open Authorization) is used to authorize and authenticate the users while the API key is used to authenticate and use the applications.

  • Adding timestamps and parameter validations. Know more