REST is acronym for REpresentational State Transfer. It is architectural style for distributed hypermedia systems and was first presented by Roy Fielding in 2000 in his famous dissertation.
Like any other architectural style, REST also does have it’s own 6 guiding constraints which must be satisfied if an interface needs to be referred as RESTful. These principles are listed below.
Guiding Principles of REST
- Client–server – By separating the user interface concerns from the data storage concerns, we improve the portability of the user interface across multiple platforms and improve scalability by simplifying the server components.
- Stateless – Each request from client to server must contain all of the information necessary to understand the request, and cannot take advantage of any stored context on the server. Session state is therefore kept entirely on the client.
- Cacheable – Cache constraints require that the data within a response to a request be implicitly or explicitly labeled as cacheable or non-cacheable. If a response is cacheable, then a client cache is given the right to reuse that response data for later, equivalent requests.
- Uniform interface – By applying the software engineering principle of generality to the component interface, the overall system architecture is simplified and the visibility of interactions is improved. In order to obtain a uniform interface, multiple architectural constraints are needed to guide the behavior of components. REST is defined by four interface constraints: identification of resources; manipulation of resources through representations; self-descriptive messages; and, hypermedia as the engine of application state.
- Layered system – The layered system style allows an architecture to be composed of hierarchical layers by constraining component behavior such that each component cannot “see” beyond the immediate layer with which they are interacting.
- Code on demand (optional) – REST allows client functionality to be extended by downloading and executing code in the form of applets or scripts. This simplifies clients by reducing the number of features required to be pre-implemented.
Common API Methods
- GET Allows to get information
- POST Used to create new information
- PUT Used to update or replace any existing resource
- DELETE Used to remove a resources
In this lab we going to create a simple REST API with a simple GET Method with the help of Amazon API Gateway.
- AWS Account
- In AWS Management Console, go to Lambda
2. Click on Create function
3. Give it a name, Select Runtime, Node.js 12.x and click on Create function
4. Once the function is created go down to the Function code
5. Here you will see the code, and you can test it, click on Test
6. Give it a event name, and click on Create
7. Click on Test again
8. And you will see the Results, and information about the function and Request ID
9. Go to API Gateway
10. Go down and click on Build REST API
11. Click OK
12. By Default you will see the Example API, in this case we want to make a New API from scratch, select New API
13. Give it a name, and click on Create API
14. Now our API is created we need to add Methods, click on Actions and then Create Method
15. Now from the Combo box, select GET and click on the check mark
16. Select the Lambda Function we create and click on Save
17. You will be asked to give permissions to the API Gateway to invoke the Lambda function, click OK
18. Now click on TEST to test our lambda function
19. And click again Test
20. If everything is working you will see the Hello from Lambda message and information about the execution
21. Now if we want to make it public, we need to Deploy the API, click on Actions, and select Deploy API
22. Select New Stage, and give it a name and click Deploy
23. You will get an URL, now we can call the API
24. Copy the URL and use in your browser and you will see the API our responding
Great we conclude the post here, now you know how to create an API and deploy it to make it public, in the next post we going deeper into the AWS Services.
- From Stages, click on Delete Stage
3. Click on API's select the API and click on Actions, Delete
5. Go to Lambda
6. Select the function and click on Actions, Delete