Parents : Web Development

Date and time note was created$= dv.current().file.ctime
Date and time note was modified$= dv.current().file.mtime

REST (representational state transfer)

[Good Resource to learn about rest](https://www.restapitutorial.com Client:The client is the user-interface to access the internet website.
Server:The server is where all the business logic lies

What is a uri and difference between URL,URI and URN?

Representations

Representations are the means to access the resoruce and manipulate the resource and also form in which the server and client exchanges the requests. The requests can be shaped in many formats. Two examples are XML and JSON. For example A person is a resource that can be accessed using the HTTP method GET and the Represntation would involve the data required and in the format in which we want it along with some meta-data.

Uniform Interface

REST has a uniform interface and by uniform interface it means that the interface for communication between client and server uses HTTP specification for communications and hence uses HTTP verbs for manipulating the resource. Common HTTP verbs - GET - PUT - POST - DELETE URI name : describes resource Response : Comes in with status and body.
Clients deliver state via body contents, query-string parameters, request headers and the requested URI (the resource name). Services deliver state to clients via body content, response codes, and response headers. This is technically referred-to as hypermedia (or hyperlinks within hypertext).

Make Your request to mean something

The HTTP verbs hold meaning and should be used accordingly

  • GET : Used to read a particular resource
  • PUT : Used to update a particular resource based on the id and can be used to create a resource too if the id is known pre-hand.
  • POST : Used to create a new resource
  • DELETE : Used to delete a particular resource based on its id.

Statelessness

Each message that is being sent to the server and also recieved by the client should contain enough context about the message and should not require any stateto be stored at the server.

When the client sends a request, the request itself contains the entire information about the request itself inside the uri,query params or body,headers

What is the difference between the resource and state ? The state can be considered as the data that is required for the current request processing while the resource is the data stored in the database which is same for all the requests no matter what. When the server recieves the req and is done processing it gives the res back to the client in the body along with status codes and uri.

Server-Client arch

REST assumes that client don’t hold direct connection to DB and should as server to make request for it. Also the server and client are separate identities.

Cacheable

Each response made must be cacheable

  1. Implicitly : without any setting from the server
  2. Explicitly : with settings from the server
  3. Negotiated : Negotiation b/w client and server for resource request cacheing

What does REST mean in REST API

In the context of a REST API (Representational State Transfer Application Programming Interface), “representational” refers to the idea that resources, data, or objects within the API are represented in a standardized format, typically as some form of structured data. This representation can be in various formats, such as JSON, XML, HTML, or even plain text, depending on the API’s design and the client’s request.

Here’s a breakdown of what “representational” means in a REST API:

  1. Resource Representation: In a RESTful system, resources (e.g., data objects, entities) are identified by URLs (Uniform Resource Locators). These resources can be complex data structures, and their state is represented in a specific format when clients request them. For example, if you have an API for managing books, a book resource might be represented as JSON like this:

    {
      "id": 1,
      "title": "The Great Gatsby",
      "author": "F. Scott Fitzgerald",
      "publication_year": 1925
    }
  2. State Transfer: The “S” in REST stands for “State.” In a RESTful API, clients interact with resources by transferring their state. This means that when a client makes a request to the API, it receives a representation of the resource’s current state. The client can then manipulate that state (e.g., updating, deleting) by sending the appropriate HTTP requests.

  3. Standardized Formats: REST APIs often use standardized data formats like JSON or XML to represent resource states. JSON, for instance, is a lightweight and widely accepted format for representing structured data, making it easy for both the server and client to understand and work with.

  4. Self-Descriptive: A key principle of REST is that representations should be self-descriptive. Clients should be able to understand the structure and meaning of the data by examining the representation itself and, if necessary, any accompanying metadata (e.g., HTTP headers).

  5. Content Negotiation: RESTful APIs often support content negotiation, which allows clients to specify the desired representation format in their requests using HTTP headers. For example, a client can request JSON or XML representation of a resource by setting the Accept header accordingly.

    GET /books/1
    Accept: application/json
    

In summary, “representational” in REST APIs emphasizes the idea that resources are presented in a structured format (representation) when clients request them, and this representation is used to transfer the state of those resources between the client and the server. The use of standardized formats and self-descriptive representations is fundamental to the design of RESTful APIs.

Serialisation

This is a process through which data of one format is converted to another format for ease of transfer usually over the network.

DTO (Data Transfer Objects)

These are flat data structures that are used to transfer data in easy to serialise (convert to specific format). The major advantage of this design Pattern is that it helps to reduce method/api calls by batching multiple parameters into one single call.

# Authentication and Authorization

Bearer Token

A Token that is used to access protected resource

OAuth

Questions

Architectural patterns

MVC Architecture ( Model-View-Controller)

Stands for Model-View-Controller

Description

  • Model- defines and changes data
  • View - describes the view/UI
  • Controller- transfers actions as events from UI/View to Model for data change.

Why

It helps us in separation of concerns of the different functionality in our code.

Reference

The Model View Controller Pattern – MVC Architecture and Frameworks Explained

Tools

Postman (API Testing Tool)

This tool I am currently using for API testing stuff. In this I learnt that I can save my projects in form of Postman Collections which in turn could hold the API endpoints of particular apis.

Also there is a option for the api examples for each endpoint basically we can create an example to test it with for immediate testing. (This would be really useful if you are testing Query Parameters in an API)

NestJs

CRUD

MVP(Minimal Viable Product)

Related

References

Footnotes