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操作。

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软件是相同的。

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

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

现在,让我们打开post man,看看它是如何工作的。

It's user interface is very simple to understand.

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

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

所有REST属性都可以在下面看到,仅用于输入URL,选择操作和发送。

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

express rest_Express / Node中用于REST API的邮递员工具相关推荐

  1. express路由子路由器_使用Express在Node中构建您的第一个路由器

    express路由子路由器 本文最初发布在Okta开发人员博客上 . 感谢您支持使SitePoint成为可能的合作伙伴. 如果最近几年您使用Node进行过任何Web开发,那么您可能已经使用过Expre ...

  2. node中的异步API

    我们都知道Node自身的执行模型是事件循环,所以事件循环是一个比较重要的知识点,理解了事件循环就能够清楚的知道代码的执行先后顺序.事件循环都有对应的观察者,然后事件循环从观察者中取出事件并执行. 01 ...

  3. node 进阶 | 通过node中如何捕获异常阐述express的特点

    node如何捕获异常 node基于js的单线程,有了非阻塞异步回调的概念,但是在处理多个并发连接时,并发环境要求高,最重要的是单线程,单核CPU,一个进程crash则web服务都crash,但是为什么 ...

  4. 使用Express在Node.js中实现非常基本的路由

    by Pau Pavón 通过保罗·帕文(PauPavón) 使用Express在Node.js中实现非常基本的路由 (Really, really basic routing in Node.js ...

  5. 使用node中的express解决vue-cli加载不到dev-server.js的问题

    在使用vue开发过程中,难免需要去本地数据地址进行请求,而原版配置在dev-server.js中,新版vue-webpack-template已经删除dev-server.js,改用webpack.d ...

  6. node中使用短信验证功能(阿里云为例)

    一.选择短信平台 短信平台有很多,这里我选择阿里云,详细步骤如下: 进入短信控制台,对要发送的短信格式进行配置,如果没有签名,需要申请签名后操作(注意:需要自己已有阿里云账号且实名认证成功) 按照如下 ...

  7. Node中HTTP模块

    文章目录 Node中的Http 一.HTTP服务器 1.http.server事件 2.http.ServerRequset请求信息 3.获取GET请求内容 4.获得POST请求内容 5.http.S ...

  8. 打开浏览器的包 node_如何发布可在浏览器和Node中使用的软件包

    打开浏览器的包 node When you create a package for others to use, you have to consider where your user will ...

  9. 【Node】常用基础 API 整理

    一.Debug 调试方法 Node 的调试方法有很多,主要分为安装 node-inspect 包调试.用 Chrome DevTools 调试和 IDE 调试,可以在官网的 Docs Debuggin ...

最新文章

  1. Android进程保活方案
  2. ubuntu 开发板ping通虚拟机挂载nfs服务器
  3. 【转】给网站添加X-UA-Compatible标签
  4. SpringBoot + Mybatis 多模块( module )项目搭建教程
  5. 视频日志之android的总结与思考
  6. Apple原装扫描二维码指定区域
  7. 多项logistic回归系数解释_逻辑回归logistic(含python代码)
  8. 关于毕业:三方协议、派遣证、干部身份等常识
  9. 异步编程举例之闹钟程序
  10. CodeForces PYM101158CSU2294 Hidden Anagrams 26进制 前缀和
  11. delete、truncate、drop的区别有哪些,该如何选择
  12. 海量数据处理-分而治之和hash映射
  13. cass块参照怎么改颜色_【干货】CASS自定义图斑填充技巧
  14. 我是怎样使用BoundsChecker的
  15. 关于公网摄像机直播公网视频直播的基本思考方法
  16. 上传图片预览(服务器版)组件
  17. uniapp 打包成H5
  18. 一种通过MQTT Broker实现远程调试、创建网络隧道的解决方案
  19. 信息定义、信息熵、信息处理及计算机科学定义
  20. 将杂乱无章的数字排序

热门文章

  1. rasa算法_(十八)基于RASA开始中文机器人实现机制
  2. repositoryitemlookupedit根据每行的id绑定数据_一种根据数据库自增ID生成唯一ID的解决方案...
  3. 开设计算机课程的必要性,学前教育专业开设计算机音乐制作课程的必要性与可行性...
  4. android viewpager画廊,Android使用ViewPager实现画廊效果
  5. python三大编程语言_程序员最需要的三种编程语言
  6. java线程堆栈_深入JVM剖析Java的线程堆栈
  7. learnpythonthehardway下载_LearnPythonTheHardWay学习笔记1:学习环境搭建
  8. html中所有的标签,HTML中的所有标签及其做用!
  9. Mysql保存是事件驱动吗_【CHRIS RICHARDSON 微服务系列】事件驱动的数据管理-5
  10. JDK源码解析之Java.util.Collection