Let us learn node.js -Part IV (Express framework)

Express Overview

Express is a minimal and flexible Node.js web application framework that provides a robust set of features to develop web and mobile applications. It facilitates the rapid development of Node based Web applications. Following are some of the core features of Express framework −

  • Allows to set up middlewares to respond to HTTP Requests.
  • Defines a routing table which is used to perform different actions based on HTTP Method and URL.
  • Allows to dynamically render HTML Pages based on passing arguments to templates.

What is REST architecture?

REST stands for REpresentational State Transfer. REST is web standards based architecture and uses HTTP Protocol. It revolves around resource where every component is a resource and a resource is accessed by a common interface using HTTP standard methods.

A REST Server simply provides access to resources and REST client accesses and modifies the resources using HTTP protocol. Here each resource is identified by URIs/ global IDs. REST uses various representation to represent a resource like text, JSON, XML but JSON is the most popular one.

 

HTTP methods

Following four HTTP methods are commonly used in REST based architecture.

  • GET – This is used to provide a read only access to a resource.
  • PUT – This is used to create a new resource.
  • DELETE – This is used to remove a resource.
  • POST – This is used to update a existing resource or create a new resource.

 

RESTful Web Services

A web service is a collection of open protocols and standards used for exchanging data between applications or systems. Software applications written in various programming languages and running on various platforms can use web services to exchange data over computer networks like the Internet in a manner similar to inter-process communication on a single computer. This interoperability (e.g., communication between Java and Python, or Windows and Linux applications) is due to the use of open standards.

Web services based on REST Architecture are known as RESTful web services. These webservices uses HTTP methods to implement the concept of REST architecture. A RESTful web service usually defines a URI, Uniform Resource Identifier a service, which provides resource representation such as JSON and set of HTTP Methods.

Body-parser which is used in line 3 is a node.js middleware for handling JSON, Raw, Text and URL encoded form data.

 

In the above example,employee id and name of the employee is send through post method to the node server and it is stored in data_to_be_stored object and it is retrieved through get method.

Note:In our examples,Postman client is used to post the data

Body-parser is used to parse the json contents and store it in the variable

Postman application or any other language can be used to for http post

(What is postman : Postman is a powerful HTTP client for testing web services. Created by Abhinav Asthana, a programmer and designer based in Bangalore, India, Postman makes it easy to test, develop and document APIs by allowing users to quickly put together both simple and complex HTTP requests.

Refer this student blog to know more about Postman https://www.digitalcrafts.com/blog/student-blog-what-postman-and-why-use-it

)

Browser or any other postman clients can be used for http get method

Add a Comment

Your email address will not be published. Required fields are marked *