Skip to main content

Koa.js


 

Koa.js

There are 5 constraints

  1. Uniform interface

  2. Stateless

  3. Cacheable

  4. Client-Server

  5. Layered System

1.Uniform interface

URIs refer to distinct services based on the http standard. HTTP requests consist of a header, body, and query parameters, whereas URI responses consist of a header, status, and body. verbs in HTTP (GET ,PUT ,POST ,DELETE)

Example: Create faculties

  • Insert new resource -

POST /faculties

  • Fetch a resource -

GET /faculties

  • Replace existing resources

PUT / faculties / {faculty id}

  • Delete resource

DELETE /faculties/{faculty id}

  • Update resource

PATCH /faculties/{faculty id}

Versioning of Rest APIs is also crucial. because it will serve in the long run when newer API versions are available Versioning is a type of text used to distinguish URIs.

As a example:

POST v1 /faculties

GET v1 /faculties

PUT v1/faculties /{faculty id}

Query parameters

In the REST API, query arguments are valid situations. Query parameters are optional parameters that are used to indicate which operations on the operation are optional. Multiple query parameters are possible.

Example: filter faculties order by name

GET v1/faculties? order-by = name

2.Stateless

A rest API is what Stateless is. They would not be allowed to carry any state. In the server, there is no client state.

Every request must be self-contained. It means that the request should include everything necessary for the request You’ll need some data that you've previously created or stored to develop this one. Assume that authentication is enabled.

Build an authentication, verify the user's identity, and then create a server session to handle the next request.

3.Client -Server

Clients interact with servers without understanding where they are or what they do.

To make the call, all you need is the URI or URL, and the communication platform is the HTTP stack.

HTTP is a protocol that sits on top of TCP. It solves practically all of the problems in the client server design, such as packet looser and stack-based ordering.

The server will have an interface, and the client will rely on it.

Clients might be any number of different people. It's a lightweight client. There is no link between the two. It is dependent on the server's interface. The server is self-contained. It has the ability to scale independently. It can alter on its own.

It may be a cloud one day and then the Google Platform the next. However, using URIs, HTTP and the HTTP stack will fix the problem. Client-server architecture is what it means.

4.Cacheable

In the REST API, homogeneity as well as statelessness regulate Cacheable. Caching is possible for all get APIs.

Account balance, for example, will not be cached due to business restrictions rather than technological constraints on caching a rest resource.

However, there may be a business limitation.

Clients can cache resources via implicit caching.

Explicit caching means that the server decides what and how to cache.

5.Layered System

A layered system emphasizes the complexity of an API, which may include several separate APIs. High scalability In a microservices system, a request can be to gather data from many services, combine it, and return it.

However, as a customer, we are unaware of any technological or architectural challenges.

Client interacts with a specific interface, which is an HTTP-specific URI-based interface.

The client knows nothing else. If there are any breaking changes, the server will release a newer version, such as v2. However, the client will continue to use version 1. Multiple layers and intermediary services can reside between the client and the server since the server is sufficiently detached.

 

 




Comments

Popular posts from this blog

 Machine Learning           What is machine learning? Machine learning (ML) is a sort of artificial intelligence (AI) that allows software programs to improve their prediction accuracy without being expressly designed to do so. In order to forecast new output values, machine learning algorithms use past data as input. Machine learning is frequently used in recommendation engines. Fraud detection, spam filtering, malware threat detection, business process automation (BPA), and predictive maintenance are all common applications. Why is machine learning important? Machine learning is significant because it allows businesses to see trends in consumer behavior and operational patterns, as well as aid in the creation of new goods. Machine learning is a major aspect of the operations of many of today's leading organizations, like Facebook, Google, and Uber. For many businesses, machine learning has become a key differentiation. What are the different types of mach...

Spring Boot Tutorial ( beginners to professionals) part -1

 Spring Boot Tutorial  This Spring boot tutorial provides you to complete lessons from beginning to professional. This spring boot tutorial is help full even you know nothing about Spring boot we going to cover all topics of Spring boot such as Advantages, history, maven, starter project wizard, spring initializer, how to create a  new spring boot project,  spring boot annotations, Spring boot dependency management, crud repository, JPA repository, etc.

Express (part-1)

 When building web apps using Node.js, setting up a server might take a long time. Because of the community's support, Node.js has matured enough over time.  Using Node.js as a backend for web apps and websites allows developers to get started quickly on their project. In this article, we'll look at Express, a Node.js web development framework that includes capabilities like routing and rendering, as well as support for REST APIs.