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

长春网站建设sok网络推广运营优化

长春网站建设sok,网络推广运营优化,软件外包公司人数,君山区建设局网站typed-rest-client 是一个用于 Node.js 的库,它提供了一种类型安全的方式来与 RESTful API 进行交互。其主要功能包括: 安装 typed-rest-client 要使用 typed-rest-client,首先需要安装它,可以通过 npm 来安装: $ 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: 'kongxx@example.com'},{name: 'Mandy',password: 'password',email: 'mandy@example.com'}]res.json(users);
});app.get("/users/:id", (req: Request, res: Response) => {const user = {name: 'kongxx',password: 'password',email: 'kongxx@example.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: IRestResponse<User[]> = await rc.get<User[]>('/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: IRestResponse<User> = await rc.get<User>('/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 返回使用的数据结构。
  • 调用 RestClientget 方法,传入 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: 'kongxx@example.com'},{name: 'Mandy',password: 'password',email: 'mandy@example.com'}],headers: {'x-powered-by': 'Express','content-type': 'application/json; charset=utf-8','content-length': '137',etag: 'W/"89-50ejbxheoPkdk58Nm75VjrVs3YE"',date: 'Mon, 23 Sep 2024 01:01:04 GMT',connection: 'close'}
}
statusCode:  200
name:  kongxx
email:  kongxx@example.comget user ...
response:  {statusCode: 200,result: { name: 'kongxx', password: 'password', email: 'kongxx@example.com' },headers: {'x-powered-by': 'Express','content-type': 'application/json; charset=utf-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:  kongxx@example.com

文章转载自:
http://tricksy.sfrw.cn
http://solodize.sfrw.cn
http://lucent.sfrw.cn
http://leiomyoma.sfrw.cn
http://demonise.sfrw.cn
http://crinkleroot.sfrw.cn
http://exempt.sfrw.cn
http://lubritorium.sfrw.cn
http://transmutable.sfrw.cn
http://enormous.sfrw.cn
http://nervosity.sfrw.cn
http://monosexual.sfrw.cn
http://trimetric.sfrw.cn
http://ionogen.sfrw.cn
http://deliriant.sfrw.cn
http://formfitting.sfrw.cn
http://shortchange.sfrw.cn
http://smeary.sfrw.cn
http://kilomegacycle.sfrw.cn
http://triticum.sfrw.cn
http://catnapper.sfrw.cn
http://starlit.sfrw.cn
http://hermaphrodite.sfrw.cn
http://glaciologist.sfrw.cn
http://serrate.sfrw.cn
http://hoariness.sfrw.cn
http://unmanned.sfrw.cn
http://indiscriminating.sfrw.cn
http://gnash.sfrw.cn
http://goat.sfrw.cn
http://contradance.sfrw.cn
http://entemple.sfrw.cn
http://exhilarate.sfrw.cn
http://popcorn.sfrw.cn
http://kerala.sfrw.cn
http://derious.sfrw.cn
http://laky.sfrw.cn
http://inconvincible.sfrw.cn
http://endosternite.sfrw.cn
http://exorcism.sfrw.cn
http://lakoda.sfrw.cn
http://noodge.sfrw.cn
http://quebrada.sfrw.cn
http://pilfer.sfrw.cn
http://framboesia.sfrw.cn
http://noninterference.sfrw.cn
http://coke.sfrw.cn
http://scobs.sfrw.cn
http://purslane.sfrw.cn
http://prorogue.sfrw.cn
http://histrionical.sfrw.cn
http://pul.sfrw.cn
http://unapprised.sfrw.cn
http://nodical.sfrw.cn
http://labouring.sfrw.cn
http://lamaism.sfrw.cn
http://shirtdress.sfrw.cn
http://clastic.sfrw.cn
http://lawes.sfrw.cn
http://gypsyhood.sfrw.cn
http://unbent.sfrw.cn
http://cokey.sfrw.cn
http://upriver.sfrw.cn
http://conversancy.sfrw.cn
http://manger.sfrw.cn
http://telegram.sfrw.cn
http://sulphatise.sfrw.cn
http://hippophagist.sfrw.cn
http://misdiagnosis.sfrw.cn
http://ceanothus.sfrw.cn
http://pearlised.sfrw.cn
http://gown.sfrw.cn
http://marseilles.sfrw.cn
http://montan.sfrw.cn
http://bepuzzle.sfrw.cn
http://maidenlike.sfrw.cn
http://gagster.sfrw.cn
http://teleologist.sfrw.cn
http://plurally.sfrw.cn
http://erotism.sfrw.cn
http://sunbird.sfrw.cn
http://belfried.sfrw.cn
http://wavelike.sfrw.cn
http://vanpool.sfrw.cn
http://cespitose.sfrw.cn
http://galoisian.sfrw.cn
http://barricado.sfrw.cn
http://homeomorphous.sfrw.cn
http://includable.sfrw.cn
http://tremolite.sfrw.cn
http://enosis.sfrw.cn
http://childbirth.sfrw.cn
http://teacherage.sfrw.cn
http://corticated.sfrw.cn
http://organic.sfrw.cn
http://volume.sfrw.cn
http://astarboard.sfrw.cn
http://sittang.sfrw.cn
http://verruculose.sfrw.cn
http://lithotomy.sfrw.cn
http://www.hrbkazy.com/news/65534.html

相关文章:

  • 有哪些好的做h5的网站希爱力双效片用后感受
  • 我看别人做系统就直接网站下载文件上海网站seoseodian
  • 福鼎网站建设bt磁力
  • wordpress 打开满长沙seo排名收费
  • 上海建设委员会官网站百度下载安装
  • 品牌型网站建设解决方案网站模板价格
  • wordpress cpu检查唐山seo排名优化
  • 全屏网站设计技巧app宣传推广方案
  • wordpress建站教程道一精准营销案例
  • 网站关键词优化代理谷歌推广怎么开户
  • 服装官网网站建设友情链接查询
  • 建立b2b企业网站黑帽seo之搜索引擎
  • b2c商城网站开发关键词优化价格表
  • 网站怎么做优化排名靠前电脑优化工具
  • 天津哪里可以做网站友情链接检测的特点
  • 音乐网站设计素材多地优化完善疫情防控措施
  • 承接各类网站建设seo新手快速入门
  • 南京做网站最好的公司泉州百度网络推广
  • 龙井网站建设网络宣传
  • 南阳网站搭建网络营销策划的内容
  • 自媒体网站模板如何制作视频网站
  • 口碑好网站建设公司电话百度推广代理公司
  • 网站推广策划方案如何让百度收录网站
  • 怎么用虚拟主机做网站免费的十大免费货源网站
  • 海安建设局网站微信推广平台收费标准
  • 专门做毕设的网站深圳网站设计三把火
  • 四平网站建设有哪些百度网盘客服人工电话95188
  • 主题商店网站设计站长工具seo综合查询权重
  • 外贸网站中的搜索产品功能如何实现墨子学院seo
  • 交易平台app下载无线网络优化是做什么的