您的位置:首页 > 博客中心 > 数据库 >

使用Node.js + MongoDB 构建restful API

时间:2022-03-14 03:45

http POST http://localhost:1337/oauth/token grant_type=password client_id=mobileV1 client_secret=abc123456 username=andrey password=simplepassword http POST http://localhost:1337/oauth/token grant_type=refresh_token client_id=mobileV1 client_secret=abc123456 refresh_token=TOKEN http http://localhost:1337/api/userinfo Authorization:‘Bearer TOKEN‘

注意!在生产环境尽量使用HTTPS,这是OAuth2的隐含内容.还有,不要不忘记对密码进行正确的哈希处理.重申一下,你可在找到这个项目.

开启本例前,你要先运行 npm install在你项目的根目录,然后运行mongod,node dataGen.js (等待它完成),然后运行node server.js.

如果有哪个部分有需要更清楚地描述,请给我留言.

总而言之,我想说node.js是一个伟大的、方便的服务器解决方案。MongoDB面向文档的方法是一个很不同寻常的但又确实是一个有用的工具。它还有很多功能我还不习惯。nodejs有一个很大的社区,有很多开源项目。例如,oauth2orize和password.js就是Jared Hanson带来精彩的项目,这很好地促进了项目的实现。


Evgeny Aleksandrov
iOS developer
evgeny@aleksandrov.ws

github.com/ealeksandrov
twitter.com/ealeksandrov

热门排行

今日推荐

热门手游