在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:nswbmw/paloma开源软件地址:https://github.com/nswbmw/paloma开源编程语言:JavaScript 100.0%开源软件介绍:PalomaAn angular-like MVC framework, based on:
Installation$ npm i paloma --save If you use Scaffoldsee create-paloma-app. ExampleCommon function const Paloma = require('paloma')
const app = new Paloma()
app.controller('indexCtrl', (ctx, next, indexService) => {
ctx.body = `Hello, ${indexService.getName()}`
})
app.service('indexService', function () {
this.getName = function () {
return 'Paloma'
}
})
app.route({
method: 'GET',
path: '/',
controller: 'indexCtrl'
})
app.listen(3000)
/*
$ curl localhost:3000
Hello, Paloma
*/ When a route is matched, its path is available at Async function const Paloma = require('paloma')
const app = new Paloma()
app.controller('indexCtrl', async (ctx, next, indexService) => {
ctx.body = await Promise.resolve(`Hello, ${indexService.getName()}`)
})
app.service('indexService', function () {
this.getName = function () {
return 'Paloma'
}
})
app.route({
method: 'GET',
path: '/',
controller: 'indexCtrl'
})
app.listen(3000)
/*
$ curl localhost:3000
Hello, Paloma
*/ or const Paloma = require('paloma')
const app = new Paloma()
app.route({
method: 'GET',
path: '/',
controller: async (ctx, next, indexService) => {
ctx.body = await Promise.resolve(`Hello, ${indexService.getName()}`)
}
})
app.service('indexService', function () {
this.getName = function () {
return 'Paloma'
}
})
app.listen(3000) routerName const Paloma = require('paloma')
const app = new Paloma()
app.route({
method: 'GET',
path: '/',
routerName: 'getHome',
controller: (ctx, next) => {
ctx.body = `routerName: ${ctx.state.routerName}`
}
})
app.listen(3000)
/*
$ curl localhost:3000
routerName: getHome
*/ Validator const Paloma = require('paloma')
const app = new Paloma()
app.controller('indexCtrl', (ctx, next) => {
ctx.body = `Hello, ${ctx.query.name}`
})
app.route({
method: 'GET',
path: '/',
controller: 'indexCtrl',
validate: {
query: {
name: { type: 'string', enum: ['tom', 'xp'], required: true }
}
}
})
app.listen(3000)
/*
$ curl localhost:3000
($.query.name: undefined) ✖ (required: true)
$ curl localhost:3000?name=tom
Hello, tom
$ curl localhost:3000?name=nswbmw
($.query.name: "nswbmw") ✖ (enum: tom,xp)
*/ More validators usage see another-json-schema. Array controllers const bodyParser = require('koa-bodyparser')
const Paloma = require('paloma')
const app = new Paloma()
app.controller('indexCtrl', (ctx, next) => {
ctx.body = ctx.request.body
})
app.route({
method: 'POST',
path: '/',
controller: [bodyParser(), 'indexCtrl']
})
app.listen(3000) More examples see test and paloma-examples. APIload(dir)Load all files by require-directory.
route(route)Register a route.
controller(name[, fn])Register or get a controller. If
service(name[, fn])Register a service constructor or get a service instance. If
factory(name, fn)Register a service factory.
provider(name, fn)Register a service provider.
constant(name, value)Register a read only value as a service.
value(name, value)Register an arbitrary value as a service.
decorator([name, ]fn)Register a decorator function that the provider will use to modify your services at creation time.
middlewares([name, ]fn)Register a middleware function. This function will be executed every time the service is accessed. Distinguish with koa's
use(fn) &see koa. LicenseMIT |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论