@mutoe/koam-core
v2.4.0
Published
Koam core package
Readme
Koam
Implement a simple Koa-like http server with zero dependencies from scratch.
THIS FRAMEWORK HAVE NOT BEEN STRICTLY TESTED, PLEASE DO NOT USE IT IN PRODUCTION ! 许多功能未经严格测试,请勿用于生产目的!
Advantage
- Lightweight (0 dependency)
- TypeScript friendly
- Built-in body parser middleware
- Built-in response time middleware
Notes
- Current only support
application/jsontype request and response body ctx.assertmust explicit declareContexttype. See microsoft/Typescript#34523app.use(async (ctx: Context, next) => { // ^^^^^^^ const val: unknown = 1.2345 // ^^^^^^^ ctx.assert(typeof val === 'number', 500) console.log(val.toFixed(2)) // ^^^ now val is number type })
Roadmap
Configuration
- [x]
app.env - [x]
app.proxy - [ ] ~~
app.keys~~ see https://github.com/mutoe/koam#3-cookie - [x]
app.proxyIpHeader - [x]
app.maxIpsCount - [x]
app.onError(error, ctx)
Application properties / methods
- [x]
app.use(middleware) - [x]
app.callback() - [x]
app.listen(...) - [x]
app.context - [ ]
app.keys= - [ ] ~~
app.on('error', error)~~ usingapp.onErrorinstead - [x]
app.address - [x]
app.port
Context properties
- [x]
ctx.req - [x]
ctx.res - [x]
ctx.request - [x]
ctx.response - [x]
ctx.state - [x]
ctx.app - [ ] ~~
ctx.app.emit~~ usingctx.throwinstead - [ ] ~~
ctx.cookies~~ see https://github.com/mutoe/koam#3-cookie - [x]
ctx.throw([status], [message], [detail])ctx.throw(appError) - [x]
ctx.assert(value, [status], [message], [detail]) - [x]
ctx.respond
Context request
- [x]
request.headersctx.headers- [ ] ~~
request.header~~ ~~ctx.header~~
- [ ] ~~
- [ ]
request.headers=- [ ] ~~
request.header=~~
- [ ] ~~
- [x]
request.get(field)ctx.get(field) - [x]
request.methodctx.method - [x]
request.method=ctx.method= - [x]
request.length - [x]
request.protocolctx.protocol - [x]
request.hostctx.host - [ ]
request.hostnamectx.hostname - [x]
request.urlctx.url - [ ] ~~
request.url=~~ ~~ctx.url=~~ - [x]
request.originalUrlctx.originalUrl - [x]
request.originctx.origin - [ ]
request.URL - [ ]
request.hrefctx.href - [x]
request.pathctx.path - [x]
request.path=ctx.path= - [x]
request.queryctx.query - [x]
request.query=ctx.query= - [x]
request.querystringctx.querystring- [x] ~~
request.search~~
- [x] ~~
- [x]
request.querystring=ctx.querystring=- [x] ~~
request.search=~~
- [x] ~~
- [x]
request.type(getmime-typeinContent-Typeheader) - [x]
request.charset(getcharsetinContent-Typeheader) - [ ]
request.freshctx.fresh - [x]
request.socketctx.socket - [ ]
request.stalectx.stale - [ ]
request.securectx.secure - [x]
request.ipctx.ip - [x]
request.ipsctx.ips - [ ]
request.subdomainsctx.subdomains - [ ]
request.is()ctx.is() - [ ]
request.accepts()ctx.accepts() - [ ]
request.acceptsEncodings()ctx.acceptsEncodings() - [ ]
request.acceptsCharsets()ctx.acceptsCharsets() - [ ]
request.acceptsLanguages()ctx.acceptsLanguages() - [ ]
request.idempotent
Context response
- [x]
response.headers- [ ] ~~
response.header~~
- [ ] ~~
- [x]
response.headerSentctx.headerSent - [x]
response.flushHeaders() - [x]
response.has(header) - [x]
response.get(header) - [x]
response.set(headers)ctx.set(headers) - [x]
response.append(header, value)ctx.append(header, value) - [x]
response.remove(header)ctx.remove(header) - [x]
response.socket - [x]
response.bodyctx.body - [x]
response.body=ctx.body=(currently only finished json body and stream) - [x]
response.statusctx.status - [x]
response.status=ctx.status= - [x]
response.messagectx.message - [x]
response.message=ctx.message= - [x]
response.lengthctx.length - [x]
response.length=ctx.length= - [x]
response.typectx.type - [x]
response.type=ctx.type= - [ ]
response.is(mimeTypes...) - [x]
response.redirect(url, [alt])ctx.redirect(url, [alt]) - [x]
response.attachment([filename])ctx.attachment([filename]) - [ ]
response.lastModified=ctx.lastModified= - [ ]
response.etag=ctx.etag= - [x]
response.vary(fields)ctx.vary(fields)
