- RPC style
- Graphql
- REST API
Six guiding constraints define a RESTful system. These constraints restrict the ways that the server can process and respond to client requests so that, by operating within these constraints, the system gains desirable non-functional properties, such as performance, scalability, simplicity, modifiability, visibility, portability, and reliability.[3] If a system violates any of the required constraints, it cannot be considered RESTful.
- Client-server Architecture
- Stateless ness
- Caching
- Layered System
- Code on Demand
- Uniform Interface
The formal REST constraints are as follows:
Client-server architecture
The principle behind the client-server constraints is the separation of concerns. Separating the user interface concerns from the data storage concerns improves the portability of the user interfaces across multiple platforms. It also improves scalability by simplifying the server components. Perhaps most significant to the Web is that the separation allows the components to evolve independently, thus supporting the Internet-scale requirement of multiple organizational domains.[3
Statelessness
The client-server communication is constrained by no client context being stored on the server between requests. Each request from any client contains all the information necessary to service the request, and the session state is held in the client. The session state can be transferred by the server to another service such as a database to maintain a persistent state for a period and allow authentication. The client begins sending requests when it is ready to make the transition to a new state. While one or more requests are outstanding, the client is considered to be in transition. The representation of each application state contains links that can be used the next time the client chooses to initiate a new state-transition.[11]
Cacheability
As on the World Wide Web, clients and intermediaries can cache responses. Responses must, implicitly or explicitly, define themselves as either cacheable or non-cacheable to prevent clients from providing stale or inappropriate data in response to further requests. Well-managed caching partially or completely eliminates some client-server interactions, further improving scalability and performance.
Layered system
A client cannot ordinarily tell whether it is connected directly to the end server, or to an intermediary along the way. If a proxy or load balancer is placed between the client and server, it won't affect their communications and there won't be a need to update the client or server code. Intermediary servers can improve system scalability by enabling load balancing and by providing shared caches. Also, security can be added as a layer on top of the web services, and then clearly separate business logic from security logic.[12] Adding security as a separate layer enforces security policies. Finally, it also means that a server can call multiple other servers to generate a response to the client.
Code on demand (optional)
Servers can temporarily extend or customize the functionality of a client by transferring executable code: for example, compiled components such as Java applets, or client-side scripts such as JavaScript.
Uniform interface
The uniform interface constraint is fundamental to the design of any RESTful system.[3] It simplifies and decouples the architecture, which enables each part to evolve independently. The four constraints for this uniform interface are:
- Resource identification in requests
- Individual resources are identified in requests, for example using URIs in RESTful Web services. The resources themselves are conceptually separate from the representations that are returned to the client. For example, the server could send data from its database as HTML, XML or as JSON—none of which are the server's internal representation.
- Resource manipulation through representations
- When a client holds a representation of a resource, including any metadata attached, it has enough information to modify or delete the resource's state.
- Self-descriptive messages
- Each message includes enough information to describe how to process the message. For example, which parser to invoke can be specified by a media type.[3]
- Hypermedia as the engine of application state (HATEOAS)
- Having accessed an initial URI for the REST application—analogous to a human Web user accessing the home page of a website—a REST client should then be able to use server-provided links dynamically to discover all the available resources it needs. As access proceeds, the server responds with text that includes hyperlinks to other resources that are currently available. There is no need for the client to be hard-coded with information regarding the structure or dynamics of the application.
What is resourse ?
Any information that can be named can be a resource: a document or image, a temporal service (e.g. “today’s weather in Los Angeles”), a collection of other resources, a non-virtual object (e.g., a person), and so on. In other words, any concept that might be the target of an author’s hypertext reference must fit within the definition of a resource. A resource is a conceptual mapping to a set of entities, not the entity that corresponds to the mapping at any particular point in time
Naming Guide
Consistency is the key
Use consistent resource naming conventions and URI formatting for minimum ambiguity and maximum readability and maintainability. You may implement below design hints to achieve consistency:
Use forward-slash (/) to indicate hierarchical relationships
Do not use trailing forward-slash (/) in URIs
Use hyphens (-) to improve the readability of URIs
Do not use underscores ( _ )
Use lowercase letters in URIs
Do not use file extensions
The Anatomy Of A Request
It’s important to know that a request is made up of four things:
- The endpoint
- The method
- The headers
- The data (or body)
What is Spring REST
The Spring framework also provides REST support. The Spring MVC module can be used to develop a REST service. It defines several annotations that you can use to develop a REST application.
What are the differences between JAX-RS and Spring REST
Although both JAX-RS and Spring REST can be used to create a RESTful service in Java, there are several differences between the two as follows:
Some important annotations in JAX-RS and Spring REST
JAX-RS | Spring REST | Use of annotation |
---|---|---|
@Get | @RequestMapping, @GetMapping | Used to specify that the method maps to an HTTP GET method |
@Post | @RequestMapping, @GetMapping | Used to specify that the method maps to an HTTP POST method |
@Path | @RequestMapping | Used to specify The URI that the method or class maps to |
@QueryParam | @RequestParam | Used to specify a query parameter |
@PathParam | @PathVariable | Used to specify a path parameter |
What is Spring Boot?
Ways to create Spring BOOT project
- Using Spring Boot CLI Tool
- Using Spring STS IDE
- Using Spring Initializr Website
- To increase Productivity.
- Easy
- Time reduction
- It avoids writing lots of boilerplate Code, Annotations and XML Configuration.
- Easy to integrate Spring Boot Application with its Spring Ecosystem like Spring JDBC, Spring ORM, Spring Data, Spring Security etc.
- It follows “Opinionated Defaults Configuration” Approach to reduce Developer effort
- It provides Embedded HTTP servers like Tomcat, Jetty etc. to develop and test our web applications very easily.
- It provides CLI (Command Line Interface) tool to develop and test Spring Boot(Java or Groovy) Applications from command prompt very easily and quickly.
- It provides lots of plugins to develop and test Spring Boot Applications very easily using Build Tools like Maven and Gradle
- It provides lots of plugins to work with embedded and in-memory Databases very easily.
Main Goal of Spring Boot:
- To avoid XML Configuration completely
- To avoid defining more Annotation Configuration(It combined some existing Spring Framework Annotations to a simple and single Annotation)
- To avoid writing lots of import statements
- To provide some defaults to quick start new projects within no time.
- To provide Opinionated Development approach.
- Spring Boot Starters
- Spring Boot AutoConfigurator
- Spring Boot CLI
- Spring Boot Actuator
- Spring Initilizr
- Spring Boot IDEs
Spring Boot Starter
- Spring core Jar file(spring-core-xx.jar)
- Spring Web Jar file(spring-web-xx.jar)
- Spring Web MVC Jar file(spring-webmvc-xx.jar)
- Servlet Jar file(servlet-xx.jar)
Spring Boot AutoConfigurator
Spring Boot CLI
Spring Boot Actuator
Spring Boot Actuator components gives many features, but two major features are
- Providing Management EndPoints to Spring Boot Applications.
- Spring Boot Applications Metrics.
Spring Boot Initilizr
- Spring Boot Initilizr With Web Interface
- Spring Boot Initilizr With IDEs/IDE Plugins
- Spring Boot Initilizr With Spring Boot CLI
- Spring Boot Initilizr With Third Party Tools
Spring Boot IDEs
No comments:
Post a Comment