当前位置: 首页 > news >正文

网站宣传与推广移动建站工具

网站宣传与推广,移动建站工具,c 语言可以做网站吗,十大外包公司排名typed-rest-client 是一个用于 Node.js 的库#xff0c;它提供了一种类型安全的方式来与 RESTful API 进行交互。其主要功能包括#xff1a; 安装 typed-rest-client 要使用 typed-rest-client#xff0c;首先需要安装它#xff0c;可以通过 npm 来安装#xff1a; $ n…typed-rest-client 是一个用于 Node.js 的库它提供了一种类型安全的方式来与 RESTful API 进行交互。其主要功能包括 安装 typed-rest-client 要使用 typed-rest-client首先需要安装它可以通过 npm 来安装 $ npm install typed-rest-client使用 typed-rest-client 这里假定有个 express 的 server 提供了两个 REST API一个是获取用户列表一个是获取用户信息。 index.ts import express, { Express, Request, Response } from express;const app: Express express(); const port process.env.PORT || 3000;app.get(/, (req: Request, res: Response) {res.send(Express TypeScript Server); });app.get(/users, (req: Request, res: Response) {const users [{name: kongxx,password: password,email: kongxxexample.com},{name: Mandy,password: password,email: mandyexample.com}]res.json(users); });app.get(/users/:id, (req: Request, res: Response) {const user {name: kongxx,password: password,email: kongxxexample.com}res.json(user); });app.listen(port, () {console.log([server]: Server is running at http://localhost:${port}); });下面是测试程序 test.ts import {RestClient, IRestResponse} from typed-rest-client/RestClient;interface User {name: string;password: string;email: string; }async function test() {const rc: RestClient new RestClient(test, http://localhost:3000);const resUsers: IRestResponseUser[] await rc.getUser[](/users);console.log(get users ...);console.log(response: , resUsers);console.log(statusCode: , resUsers.statusCode);console.log(name: , resUsers.result[0]?.name);console.log(email: , resUsers.result[0]?.email);const resUser: IRestResponseUser await rc.getUser(/users/1);console.log(get user ...);console.log(response: , resUser);console.log(statusCode: , resUser.statusCode);console.log(name: , resUser.result?.name);console.log(email: , resUser.result?.email); }test();这里首先定义了一个 interface描述了 REST API 返回使用的数据结构。调用 RestClient 的 get 方法传入 URL 和返回的数据类型返回一个 IRestResponse 对象IRestResponse 对象包含了 HTTP 响应的状态码、响应头和响应体。通过 statusCode 属性可以获取到 HTTP 响应的状态码。通过 headers 属性可以获取到 HTTP 响应头。通过 result 属性可以获取到响应体中的数据。 测试 首先启动express server。 $ npm run dev运行测试程序 $ npm install -g typescript $ tsc src/test.ts node src/test.jsget users ... response: {statusCode: 200,result: [{name: kongxx,password: password,email: kongxxexample.com},{name: Mandy,password: password,email: mandyexample.com}],headers: {x-powered-by: Express,content-type: application/json; charsetutf-8,content-length: 137,etag: W/89-50ejbxheoPkdk58Nm75VjrVs3YE,date: Mon, 23 Sep 2024 01:01:04 GMT,connection: close} } statusCode: 200 name: kongxx email: kongxxexample.comget user ... response: {statusCode: 200,result: { name: kongxx, password: password, email: kongxxexample.com },headers: {x-powered-by: Express,content-type: application/json; charsetutf-8,content-length: 68,etag: W/44-WML8FV1wUhoW//8kQuCB8B/FWaQ,date: Mon, 23 Sep 2024 01:01:04 GMT,connection: close} } statusCode: 200 name: kongxx email: kongxxexample.com
http://www.dnsts.com.cn/news/85926.html

相关文章:

  • asp网站安装教程wordpress菜单 标题属性
  • 国外网站卖货平台wordpress不停刷y
  • 做公司 网站建设价格低网络工程技术课设报告
  • 重庆建设工程查询网站专业微信网站
  • crm客户系统南通网站seo
  • 西安做网站的公司电话网站禁用右键
  • 网站推广品牌建设微官网登录入口
  • 厦门网络公司网站网站轮播广告代码
  • 安阳网站制作价格10大物业管理系统
  • 洛阳网站建设哪家便宜中国产品网网址
  • 崇州园区营销网站建设如何在各个购物网站之间做差价
  • 如何自建网站卖产品成功的网站建设
  • 正规网站备案代理做网站的html框架
  • pc网站模板中国建设银行官网站大同
  • 兰州网站程序建设杭州做搜索引擎网站的公司
  • 网站根验证文件在哪国家建设材料检测网站
  • php网站攻击网络广告营销推广
  • ps做网站页面设置为多大长沙市规划建设局网站
  • 阐述商业网站开发岗位需求分析汽车价格网
  • 为农村建设网站报告深圳联雅做网站怎么样
  • seo网站营销推广公司商城开发分销系统
  • 中国各大网站名称做合约交易哪个网站好
  • 多就能自己做网站优化合作平台
  • 铜陵网站开发乐清网站开发
  • 重庆帝一网络网站建设专家wordpress漏洞总结
  • 套做网站无锡做网站哪个公司好
  • 吉林手机版建站系统信息珠海网络推广
  • 景区网站的作用wordpress 仿微信主题
  • 网站建设工作室wp主题模板设计师 推荐 网站
  • 代理做网站合适吗wordpress 分享 插件