Back to Browse

107. Postman, GET & POST Requests

7.9K views
Premiered Jan 31, 2019
16:59

Week 3: Day 2 Section 12: Intro to Node, Mongo, & REST APIs Tutorial 107: Postman, GET & POST Requests In this tutorial, we are going to create our very first API or server. For this, we will be using npm as it allows us to install packages for the project. To download any npm package : Visit npmjs.com: It is a package manager for the JavaScript programming language. Search for the required package in the search box. Several packages matching the requirement are shown sorted on the basis of popularity.(you can also sort them on the basis of optimal, relevance, and maintenance.) To create our new project we will create a folder and add a javascript file to it. Now we will initialize this as an npm or node project by typing npm init. npm init is a convenient way of scaffolding your package. json; you may need to run it every time you are starting a new project. After this, we would be given to fill up a few details about our project. Now our project folder contains two files .json file and a server.js file. Here we will be working with a package called Express. Express is a web application framework for Node. js, released as free and open-source software under the MIT License. It is designed for building web applications and APIs. It has been called the de facto standard server framework for Node. The express framework is built on top of the node. js framework and helps in the fast-tracking development of server-based applications. Routes are used to divert users to different parts of the web applications based on the request made. Express and node go hand in hand. Here we are going to use Express to handle incoming web requests. To install Express: Go to the terminal inside the directory and package.json file Type npm install --save express Before version 5, NPM simply installed a package under node_modules by default. The --save option instructed NPM to include the package inside of the dependencies section of your package. json automatically, thus saving you an additional step. Now our project folder contains another folder named node_modules with express. We have got the node package manager initialized inside our project with the node_modules folder and a package JSON. var express = require(‘express’); Here the required keyword grabs the package out of the nodel_module folder and stores it in a variable named express. var app = express(); Here we define express as a function and store it in an app. app.get(‘/’ , function(request,response) { You can make requests to APIs in Postman. An API request allows you to retrieve data from a data source, or to send data. GET methods to retrieve data from an API. POST sends new data to an API. If any kind of response is coming from a client and is hitting the base URL, the request is then passed in. Request from the client is getting dropped in this function as a parameter. app.send(‘My first API’); You can make requests to APIs in Postman. An API request allows you to retrieve data from a data source, or to send data. POST sends new data to an API. app.listen(3000,function(){ console.log(“....”);}) The app. listen() function creates the Node. js web server at the specified host and port. It is identical to Node's HTTP. Full Stack Web Development in Just 3 weeks Published by WB Web, Under free promotions, Watch All the videos for free for a limited time. You can buy the course from Udemy for lifetime access. Udemy Course Link: https://www.udemy.com/ultimate-web/ Content Credit: Mark Price https://www.devslopes.com/ Hosted By WB Web Development Solutions

Download

0 formats

No download links available.

107. Postman, GET & POST Requests | NatokHD