express rest_Express / Node中用于REST API的郵遞員工具

express rest

When dealing with routes (like in express), we may use any of the REST verbs and at times, the browser is limited to facilitate testing the routes/REST API.

在處理路由時(如快速表達),我們可以使用任何REST動詞,有時瀏覽器會受到限制,以方便測試路由/ REST API。

REST API的郵遞員工具 (Postman tool for REST API)

POSTMAN is a tool which helps us easily work with REST API. It has it's desktop and web version (chrome extension).

POSTMAN是可幫助我們輕松使用REST API的工具。 它具有桌面版和網絡版(chrome擴展名)。

Before we see how it works, let's remind ourselves about the various REST API operations according to courser.org node.js tutorial video.

在了解其工作原理之前,讓我們根據courser.org node.js教程視頻提醒自己各種REST API操作。

Postman tool for REST API Image 1

Take Note! You should have Node js installed in your computer.

做記錄! 您應該在計算機中安裝Node js。

With Node.js already up and running, let's get started.

在Node.js已經啟動并運行的情況下,讓我們開始吧。

Download POSTMAN follow the installation procedure to install or download on the web as chrome extension...

按照安裝程序下載POSTMAN ,以chrome擴展程序的形式在網絡上安裝或下載...

I personally used the web version, but using the PC software is the same.

我個人使用過網絡版本,但是使用PC軟件是相同的。

Postman tool for REST API Image 2

Wait for a while as it downloads.

等待下載。

NB: Internet required!

注意:需要互聯網!

In this article we’re going to create an express route or REST API and use POSTMAN. Open a text editor and type the following code and save it with the file name app.js:

在本文中,我們將創建一個快速路由或REST API并使用POSTMAN 。 打開文本編輯器,輸入以下代碼,并將其保存為文件名app.js:

const express = require ('express');
const http = require ('http');
const morgan = require('morgan');
const bodyParser = require ('body-parser');
const hostname = 'localhost';
const port = 8080;
const app = express();
app.use (morgan('dev'));
app.use (bodyParser.json ());
app.all('/dishes', (req,res,next) => {
res.statusCode = 200;
res.setHeader ('Content-Type', 'text/plain');
next();
} );
app.get ('/dishes', (req,res,next) => {  // get operation
res.end ('will send all the dishes to you!');
} );
app.post ('/dishes', (req,res,next) => { //post operation
res.end ('will add the dish:' + req.body.name + 'with details:' + req.body.description );
});
app.put ('/dishes', (req,res,next) => { //put opration
res.statusCode = 403;
res.end ('put operation not supported on dishes');
});
app.delete ('/dishes', (req,res,next) => {
res.end ('deleting all dishes!');
} );
app.get ('/dishes/:dishId', (req,res,next) => {
res.end ('will send will send details of the dish:' + req.params.dishId + 'to you' );
} );
app.post ('/dishes/:dishId', (req,res,next) => {
res.statusCode = 403;
res.end ('post operation not supported on /dishes/' + req.params.dishId);
});
app.put ('/dishes/:dishId', (req,res,next) => {
res.write('updating the dish:' + req.params.dishId)
res.end ('will update the dish:' + req.body.name + 'with details' + req.body.description );
});
app.delete ('/dishes/:dishId', (req,res,next) => {
res.end ('deleting dish:' + req.params.dishId);
} );
app.use (express.static (__dirname + '/tools'));
app.use ( (req,res,next) => {   
res.statusCode = 200;
res.setHeader ( 'content-type', 'text/html' );
res.end ('<html><body><h1>This is an express Server</h1></body></html>')
});
const server = http.createServer (app);
server.listen (port,hostname, () =>{
console.log (`server running at http://${hostname}:${port}`)
} );

The file should be saved in your default node.js project directory.

該文件應保存在默認的node.js項目目錄中。

Initiate the JavaScript file at the console by typing node app.js

通過鍵入節點app.js在控制臺上啟動JavaScript文件

Take Note!: Your command line directory should be same with node js module/project directory.

注意!:您的命令行目錄應與node js module / project目錄相同。

Open your browser and navigate to http://localhost:8080

打開瀏覽器并導航到http:// localhost:8080

Postman tool for REST API Image 3

Now, let's open post man and see how it works.

現在,讓我們打開post man,看看它是如何工作的。

It's user interface is very simple to understand.

它的用戶界面很容易理解。

Postman tool for REST API Image 4

All the REST properties can be seen below, left just to input URL, select operation, and send.

所有REST屬性都可以在下面看到,僅用于輸入URL,選擇操作和發送。

Postman tool for REST API Image 5
Postman tool for REST API Image 6

Thanks for coding with me. Your comments are most welcome.

感謝您與我一起編碼。 非常歡迎您發表評論。

翻譯自: https://www.includehelp.com/node-js/postman-tool-for-rest-api-in-express-node.aspx

express rest

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/541608.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/541608.shtml
英文地址,請注明出處:http://en.pswp.cn/news/541608.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

我們在使用計算機時,不能做什么?,11秋季學期計算機應用技術基礎學習周期_01任務-在線作業[1]1...

1.選購顯示器應優先考慮顯示器的( B )性能指標選A.顯示器的防輻射指標B. 顯示器的帶寬C. 顯示器的刷新率D. 顯示器的尺寸2. 一個聲音文件采用雙聲道8位采樣精度、22K采樣頻率錄音&#xff0c;它的大小是5M&#xff0c;如果采用單聲道16位采樣精度、44K采樣頻率錄音&#xff0c;…

按一個按鈕會隨機死人_《饑荒》那些年坑爹的隨機地圖,最后一個簡直笑死人...

饑荒是一款隨機性很強的游戲&#xff0c;這也是饑荒這款游戲相當耐玩的主要原因。別的不說小編敢保證隨機開圖的話你絕對找不到兩張一模一樣的地圖。地圖上的資源也會大不相同。不管是稀有的各種奇遇還是基礎資源的刷新數量都是完全不同的。當然對于一些基礎資源玩家們并沒有多…

介詞at_介詞邏輯| 離散數學

介詞at介詞或陳述 (Preposition or Statement) A preposition is a definition sentence which is true or false but not both. 介詞是一個定義語句&#xff0c;它是對還是錯&#xff0c;但不能同時包含兩者。 For example: The following 8 sentences, 例如&#xff1a;以下…

職稱計算機提前考試試卷,職稱計算機考試多項選擇考試卷模擬考^試題

《職稱計算機考試多項選擇考試卷模擬考^試題》由會員分享&#xff0c;可在線閱讀&#xff0c;更多相關《職稱計算機考試多項選擇考試卷模擬考^試題(8頁珍藏版)》請在人人文庫網上搜索。1、姓名&#xff1a;________________ 班級&#xff1a;________________ 學號&#xff1a;…

形象易懂講解算法I——小波變換

https://zhuanlan.zhihu.com/p/22450818?referdong5 最早發于回答&#xff1a;能不能通俗的講解下傅立葉分析和小波分析之間的關系&#xff1f; - 咚懂咚懂咚的回答現收入專欄。從傅里葉變換到小波變換&#xff0c;并不是一個完全抽象的東西&#xff0c;可以講得很形象。小波變…

r語言安裝ipsolve_R語言矩陣操作之矩陣運算

1.轉置運算對于矩陣A&#xff0c;函數t(A)表示矩陣A的轉置&#xff0c;如&#xff1a;> Amatrix(1:6,nrow2);> A;[,1] [,2] [,3][1,] 1 3 5[2,] 2 4 6> t(A);[,1] [,2][1,] 1 2[2,] 3 4[3,] 5 62.求方陣的行列式函數det()是求矩陣…

使用Linux命令行歸檔文件

存檔文件 (Archiving Files) As we already understand what Compression (Compression techniques in Linux) is? We shall learn about Archives. We prefer compression as it is convenient to send file compressed through a network but sometimes it is not a smart w…

http緩存機制之304狀態碼

在網上看到一篇關于解釋瀏覽器緩存更新機制304狀態碼的文章&#xff0c;里面說如果請求頭中的If-Modified-Since字段和If-None-Match字段的值分別和響應頭中的Last-Modified字段和Etag字段值一致&#xff0c;服務器就會返回304狀態碼(無響應體)&#xff0c;瀏覽器就從本地讀取緩…

東北大學 計算機技術導師,報考東北大學 計算機技術 329分 求調劑相關專業

自薦類型&#xff1a;碩士自薦報考院校&#xff1a;東北大學報考專業&#xff1a;(專業碩士)計算機技術[085211]本科院校&#xff1a;沈陽工程學院本科專業&#xff1a;計算機科學與技術初試成績&#xff1a;總分&#xff1a;329政治&#xff1a;69 英語&#xff1a;71 …

c語言i++和++i程序_使用C ++程序修改鏈接列表的內容

c語言i和i程序Problem statement: 問題陳述&#xff1a; Given a linked list, you modified that linked list in such a way that the elements of the first half of that linked list are the difference of the first node to the last node and next node is the differ…

原生js設置div隱藏或者顯示_10種JS控制DIV的顯示隱藏代碼

div隱藏與顯示#menus {background-color: #c4cff0;}function Layer_HideOrShow(cur_div){ var currentdocument.getElementById(cur_div);if(current.style.visibility"hidden"){current.style.visibility "visible";}else{current.style.visibility "…

計算機工作對身體有害嗎,在電腦前長時間工作會對身體有害處嗎?

病情分析&#xff1a;目前,電腦對人體生理和心理方面的負面影響已日益受到人們的重視.為此科學使用電腦,減少電腦和網絡的危害是十分必要的.指導意見&#xff1a;一是要增強自我保健意識工作間隙注意適當休息,一般來說,電腦操作人員在連續工作1小時后應該休息10分鐘左右.并且最…

Java LinkedList getFirst()方法與示例

LinkedList getFirst()方法 (LinkedList getFirst() method) This method is available in package java.util.LinkedList. 軟件包java.util.LinkedList中提供了此方法。 This method is used to return the first or initial or beginning element of the linked list. 此方法…

C++第15周(春)項目2 - 用文件保存的學生名單

課程首頁在&#xff1a;http://blog.csdn.net/sxhelijian/article/details/11890759。內有完整教學方案及資源鏈接本程序中須要的相關文件。請到http://pan.baidu.com/s/1qW59HTi下載。【項目2-用文件保存的學生名單】  文件score.dat中保存的是若干名學生的姓名和C課、高數和…

計算機選配 注意事項,選擇鼠標注意事項有哪些

選擇鼠標注意事項有哪些每臺電腦旁邊都有了一個忠實的伴侶&#xff0c;那就是“Mouse”--鼠標。選擇鼠標最重要的一點就是質量&#xff0c;無論它的功能有多強大、外形多漂亮&#xff0c;如果質量不好那么一切都不用考慮了。那么&#xff0c;選擇鼠標注意事項有哪些?筆記本鼠標…

js 驗證護照_護照本地策略第2部分| Node.js

js 驗證護照In my last article (Passport local strategy section 1 | Node.js), we started the implementation of the passport-local authentication strategy. We also looked at the various requirements to get started with the login form. In this article, we wil…

svn版利用什么技術實現_金蔥粉涂料印花利用了什么技術?

金蔥粉涂料印花利用了什么技術:金蔥粉用涂料而不是用染料來生產印花布已經非常廣泛&#xff0c;以致開始把它當作一種獨立的印花方式。涂料印花是用涂料直接印花&#xff0c;該工藝通常叫做干法印花&#xff0c;以區別于濕法印花(或染料印花)。通過比較同一塊織物上印花部位和未…

網站換服務器需要注意什么問題,網站更換服務器要注意哪些事項

原標題&#xff1a;網站更換服務器要注意哪些事項網站在運營的過程中&#xff0c;出于某種考慮&#xff0c;我們會將網站進行服務器的變更&#xff0c;那么在進行服務器變成過程中&#xff0c;需要注意哪些事項。一、如果是跨服務商更換網站服務器&#xff0c;需要做備案遷移。…

json轉string示例_C.示例中的String.Insert()方法

json轉string示例C&#xff03;String.Insert()方法 (C# String.Insert() Method) String.Insert() method is used to insert a string in an existence string at specified index and returns a new string. String.Insert()方法用于在指定索引處的存在字符串中插入一個字符…

kafka分區與分組原理_大數據技術-Kafka入門

在大數據學習當中&#xff0c;主要的學習重點就是大數據技術框架&#xff0c;針對于大數據處理的不同環節&#xff0c;需要不同的技術框架來解決問題。以Kafka來說&#xff0c;主要就是針對于實時消息處理&#xff0c;在大數據平臺當中的應用也很廣泛。大數據學習一般都有哪些內…