开源实时应用程序和REST api Web开发框架(诺禾)

feathers是一个轻量级的Web框架,在Github上相当受欢迎,stars数高达12.6k+,开源遵循MIT License,feathers使用JavaScript或TypeScript创建实时应用程序和REST api。Feathers可以与任何后端技术交互,支持超过12个数据库,与任何前端技术如React、VueJS、Angular、React Native、Android或iOS一起进行开发。

开源实时应用程序和REST api Web开发框架(js&ts)——feathers
Github
https://github.com/feathersjs/feathers

feathers有何与众不同?
JavaScript和TypeScript构建
使用最新的语言特性,Feathers是一个小的库,它提供了创建复杂应用程序的结构,但又足够灵活,不会妨碍开发。

灵活的插件
拥有大量插件生态系统

多数据库支持
Feathers为12个以上的数据库提供了现成的适配器。可以在一个应用程序中拥有多个数据库,并且由于一致的查询接口,可以毫不费力地将它们协同起来。

兼容性好
Feathers可以用同样的方式在服务器上使用Node.js,在浏览器框架中使用React、Angular、VueJS,或者在移动设备上使用React Native。

面向服务的模式
Feathers从一开始就提供了构建面向服务的应用程序的结构。当你最终需要将你的应用分解成微服务时,很容易过渡。

即时实时REST api
Feathers通过服务提供即时CRUD功能,通过websockets自动公开RESTful API和实时后端

开源实时应用程序和REST api Web开发框架(js&ts)——feathers
创建第一个应用
$ npm install -g @feathersjs/cli

yarn global add @feathersjs/cli

$ mkdir my-app
$ cd my-app
$ feathers generate app
$ npm start

yarn start

开源实时应用程序和REST api Web开发框架(js&ts)——feathers
开源实时应用程序和REST api Web开发框架(js&ts)——feathers
开源实时应用程序和REST api Web开发框架(js&ts)——feathers
开源实时应用程序和REST api Web开发框架(js&ts)——feathers
开源实时应用程序和REST api Web开发框架(js&ts)——feathers
下面创建一个带有简单消息服务的Feathers应用程序,该服务允许创建新消息并查找所有现有消息

扫描二维码关注公众号,回复: 11564253 查看本文章

const feathers = require(’@feathersjs/feathers’);
const app = feathers();

// 允许创建新消息的消息服务
// 并返回所有现有的消息
class MessageService {
constructor() {
this.messages = [];
}

async find () {
// 只要返回我们所有的信息
return this.messages;
}

async create (data) {
// 新消息是带有唯一标识符的合并数据
// 使用消息长度,因为只要我们添加一个消息,它就会改变
const message = {
id: this.messages.length,
text: data.text
}

// 向列表中添加新消息
this.messages.push(message);

return message;

}
}

// 在Feathers应用程序上注册消息服务
app.use(‘messages’, new MessageService());

// 每次创建新消息时记录日志
app.service(‘messages’).on(‘created’, message => {
console.log(‘A new message has been created’, message);
});

// 创建新消息并记录日志的函数
// 所有现有的消息
const main = async () => {
// 在消息服务上创建一个新消息
await app.service(‘messages’).create({
text: ‘Hello Feathers’
});

await app.service(‘messages’).create({
text: ‘Hello again’
});

// 查找所有现有消息
const messages = await app.service(‘messages’).find();

console.log(‘All messages’, messages);
};

main();
总结
详细的使用以及开发流程可以参考详细的官方文档,包括授权、安全性、单元测试、服务等等,对JavaScript和Typescript以及Web开发感兴趣的小伙伴们不要错过啦!

猜你喜欢

转载自blog.csdn.net/yyone123/article/details/107914211