2018 TypeScript Update(4)LDAPJS and RESTful and Async

本文介绍了如何使用TypeScript和RESTful技术构建Web服务。通过实际项目示例,讲解了如何搭建开发环境、生成Swagger文档及启动项目。此外,还深入探讨了异步编程在TypeScript中的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

2018 TypeScript Update(4)LDAPJS and RESTful and Async

LDAP Guide
http://ldapjs.org/guide.html
LDAP - Lightweight Directory Access Protocol

Understand a Simple RESTful TypeScript
https://github.com/vrudikov/typescript-rest-boilerplate

> git clone https://github.com/vrudikov/typescript-rest-boilerplate

Go to that project, install the dependency
> npm install

Generate the swagger document
> npm run swagger

Start the Project
> npm start

Visit the URL
http://localhost:3000/

Some Tests Fail, Not Latest
Check this project
https://github.com/w3tecch/express-typescript-boilerplate

This Project seems great.

Understand Async in TypeScript
http://www.webhek.com/post/javascript-async-await-2.html

async means this function is async, await can only be inside this function.
await means wait for promise return value
await will follow by promise

Example
Begin with a simple example
var sleep = function(time) {
Return new Promise(function(resolve, reject){
setTimeout(function() { resolve();}, time);
})
}

var start = async function() {
console.log(’start’);
await sleep(3000);
console.log(‘end’);
}

Start();

Get Return Value
var sleep = function(time){
return new Promise(function(resolve, reject) {
setTimeout(function(){ resolve(‘ok’); }, time);
})
}

var start = async function() {
let result = await sleep(3000);
console.log(result);
};

Get the Error
var sleep = function (time) {
return new Promise(function(resolve, reject) {
setTimeout(function() { reject(‘error’); }, time);
})
};
var start = async function(){
try{
console.log(‘start’);
await sleep(3000); //error
console.log(‘end’);
}catch(err){
console.log(err);
}
};


References:
http://ldapjs.org/
http://ldapjs.org/guide.html

https://github.com/vrudikov/typescript-rest-boilerplate
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值