Idea on REST API



I am going to focusing on the rest API within today’s blog. Rest API is also known as restful API among the programmers. Let's take those word separately to understand what is going here it is.

 

API

API is  stand for an application programming interface. Usually the API is some kind of protocol some  set of rules  for building and integrating the apps. API decide how to connect the data provider and the data user  of Web Services. IT highlights that it the content that the producer and consumer must provide at that process within this communication. actually the API is some kind of mediator between the users and the resources on the web services while maintaining the security control and authentication by determining who get access to work properly. API can easily understand that  what the consumer needs it and easily take those details from the producer By its own ways. 

 


 

REST

REST stands for representational state transfer. It is just not a protocol standard like API. API developers implement the rest with the API in several ways. After receiving the request from the consumer that I have mentioned before restful API transfers representation of the state of this producer for that particular consumer. The architectural style of REST helps in leveraging the lesser use of bandwidth to make an application more suitable for the internet. 

When we are considering about this information, it is delivered from several kinds of formats. The main kinds of formats are, HTTP: JSON, HTML, XLT, Python, PHP, or plain text. among them Jason  or the JavaScript  Object Notation can be considered as the most using and the most easiest one among them. within the previous blog I have explained you about the JavaScript initial steps and how to create an initial web function by using JavaScript. in here also some knowledge of JavaScript in order to understand the  performance of Jason files.  you can easily view my previous blog and the GIT examples by following this link,

Click here move to GIT-Repository


Rest API  is built up with rest architectural style and it allows the interactions with others for restful Web Services. In here we need to consider about the headers and the necessary parameters of JSON files because they are carrying some kind of necessary data such as the request’s metadata, the authentication, URI, and so on. there are two kind of headers which are named as response headers and request headers. also they have their own details about  their own things.

 


Also there are some necessity is that we need to consider when some API to be considered  as restful. Always it need to have a client server architecture which the requests are managed by http. The system must be layered into the hierarchy and it may maintain each type of servers(responsible for security, load-balancing and so on). Also We need maintain A uniform interface between components so that information is transferred in a standard form.

  • resources requested need to be identifiable and separate from the representations sent to the client.
  • resources can be manipulated by the client via the representation 
  • self-descriptive messages returned to the client have enough information to describe how the client should process it.
  • hypertext/hypermedia is available, meaning that after accessing a resource the client should be able to use hyperlinks to find all other currently available actions they can take.[02]

Though the REST API has these criteria to conform to, it is still considered easier to use than a prescribed protocols ( take SOAP as example ).So after confirming those necessary  kinds of things rest APIS  are some kind of  scalable  platform with  interest performances. it can be used for all the kind of mobile application development and other IOTs as well.



The initial steps to create rest API.

As I have used the JavaScript  for the last blogs here also I am going to focus on JavaScript and node JS Which is one of the most powerful frameworks of JavaScript. by using the node JS we are going to have a look on rest API. for this task you need to install  the node.js Framework from Its official site.

Node JS official Download

Also install the NPM (Node Package Manager) Installation. If you are using some previous kind of not this version you need to install 'npm' separately by using command but if you are using the node.js that I have given you from the above link the 'npm' is already installed as an default package  under node JS. Otherwise you can use the following command for installing process.

>npm install pkg_Name 

So please install some IDE to have a look on node JS( WebStorm is recommended). 

Create a project directory, which will consist of all the files present in the project. Then, open commands prompt and navigate to the project directory. You know how to navigate the proper place by using command easily. also you can use command CD for navigating back as well at the command prompt. Now we can initiate a project by using 'npm' command. it will simply ask  to enter some initial details regarding the project called metadata.

>npm init

So then the JavaScript will ask you to confirm  the details. then please enter ‘Y’ necessary confirmation letter as it is asking.

Now it is the time to install the express JS on your project.  express is also a framework Of node.js This web framework will allow you to create Restful APIs, with the help of helper methods, middle layers to configure your application. Also for creating the structures of the blueprints of the JavaScript objects that validates the key information you can install the joy and also the monitoring package cold 'nodemon' which manages  all the files within your project at every stages when you make an update it will get that an make necessary  configurations   at the process. Use the following commands for that.

>npm i joi

>npm i -g nodemon

Then you can will you your  package JSON file in order to clarify the things you have entered and everything is ok.

package.json

 

2

3

4

5

6

7

8

9

10

11

12

13

14

15

{

"name": "lab_05_IT19062884",

"version": "1.0.0",

"description": "Lab on Rest Api",

"main": "script.js",

"scripts": {

"test": "echo \"Error: no test specified\" && exit 1"

},

"author": "Ruvindu_Kaushalya",

"license": "ISC",

"dependencies": {

"express": "^4.17.1",

"joi": "^14.3.1"

}

}

So here after you can implement your Script.js  file. I am not going to show you that because it is depend on your needs and the type of data that you need to enter for your application. create it with necessary methods in order to have a proper methods such as get, set. After that you can take your handlers simply by adding some extension for your browser. For crome we can use an simple extinction,

Google Chrome extension

For starting the service simply enter,

>node script.js

>Listening to port 8080..

Now all the initial steps are completely over so it is the time to test Some sort of initial crud operations,  get, post, update and delete. 

for the process of getting the details you can simply choose get option from the drop down and and for the post you can simply select Post from the dropdown and enter the details on the the text area and you can simply click send And check whether it is included. Also you can select put and enter necessary details with the correct ID and URL for the updating process. For deleting process also you can select delete from the dropdown and simply choose the  URL along with the particular ID to process that. After all you can check the remaining objects  by calling the get method again. 

In here you must know that there are  several methods to make this process and confirm the performance of rest API. at the very last stage I was focusing for  a one particular process  on that.

If you face any issue or any conformation Please contact, E-Mail Contact



References

[1]https://www.edureka.co
[2]https://www.redhat.com/


Comments

Popular posts from this blog