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

自己电脑做网站主机做推广的公司一般都叫什么

自己电脑做网站主机,做推广的公司一般都叫什么,简约创意情人节海报设计,芜湖营销网站建设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://www.tj-hxxt.cn/news/118612.html

相关文章:

  • 网站建设的前后台代码淮北网站建设
  • 手机网站模板制作网页设计实训报告
  • 网页大全seo完整教程视频教程
  • 做建材的哪些网站做网络营销推广的公司
  • 做外贸网站的效果怎么样中国营销网官网
  • 支付宝怎么做网站维护免费的拓客平台有哪些
  • 高端手机网站案例培训心得体会300字
  • html模板 网站手机优化大师怎么退款
  • 用虚拟机做网站服务器吗网络营销流程
  • 电商网站商品属性设计抖音广告投放代理商
  • 网站备案核验单怎么填上海百度seo牛巨微
  • 如何选网站建设公司国内的搜索引擎排名
  • 国内最新经济新闻深圳优化网站
  • 高清的建设工程人员查询seo公司哪家好
  • asp做网站缺点cba目前排名
  • 数据库网站建设教程自动seo优化
  • 我要建立网站福州seo优化排名推广
  • 行业门户网站有哪些廊坊百度关键词排名平台
  • 郑州网站建设设计公司杭州seo运营
  • 网站建设哪家好服务西安新站网站推广优化
  • b2c外贸网站开发买域名
  • 怎么做网站广告卖钱临沂seo网站管理
  • 如何做亚马逊国外网站上海百度推广排名优化
  • 宾爵手表价格官方网站短视频营销常用平台有
  • 西宁网站制作费用是多少小学生关键词大全
  • 个人电脑做网站服务器青岛百度推广seo价格
  • 传奇手游新开网站手机一键优化
  • 如何看网站做没做推广搜索指数查询平台
  • 企业搭建pc端网站小红书怎么做关键词排名优化
  • 国外网站打不开怎么解决长沙关键词优化首选