Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/novi/Kunugi
Minimal web framework and middleware for Swift
https://github.com/novi/Kunugi
Last synced: 2 months ago
JSON representation
Minimal web framework and middleware for Swift
- Host: GitHub
- URL: https://github.com/novi/Kunugi
- Owner: novi
- License: mit
- Archived: true
- Created: 2016-01-03T12:31:55.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-03-31T16:22:37.000Z (almost 9 years ago)
- Last Synced: 2024-10-16T14:20:34.317Z (3 months ago)
- Language: Swift
- Homepage:
- Size: 27.3 KB
- Stars: 34
- Watchers: 10
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-swift-cn - Kunugi - Minimal web framework and middleware for Swift. (Libs / Network)
README
# Kunugi
Kunugi(椚) is minimal web framework and middleware systems for Swift. This is inpired by Node.js' [Koa](http://koajs.com).
Kunugi doesn't provide http server its self. It provides [Nest Interface](https://github.com/nestproject/Nest).
See some example projects until documents is done.
* [Kunugi-Examples](https://github.com/novi/Kunugi-Examples)
* [todoapi](https://github.com/novi/todoapi-example/tree/experimental/todoapi/todoapi)_Note:_ This is in early development project.
# Usage
Define your context and app.
```swift
import Kunugi
import Nestclass Context: ContextBox {
var context: [ContextType] = []
var request: Request
var method: Method
var path: String
var parameters: [String: String] = [:]
init(request: Request) {
self.request = request
self.path = request.path
self.method = Method(request.method)
}
}class App: AppType {
var wrap: [WrapMiddleware] = []
var middleware: [MiddlewareType] = []
func use(m: WrapMiddleware) {
wrap.append(m)
}
func use(m: MiddlewareType) {
middleware.append(m)
}
var application: Application {
... // root handler for your server
}
}```
Create your request handler.
```swift
// Closure style handler with routes
let router = Router()
router.get("/hello") { ctx in
return .Respond(Response(.Ok, body: "world"))
}// Controller style handler
struct HelloController: ControllerMiddleware, AnyRequestHandleable {
func post(ctx: ContextBox) throws -> MiddlewareResult {
return .Respond(Response(.Ok, body: "hello world"))
}
}```
Stack your middleware to the app and start your server.
```swift
let app = App()app.use(Logger())
app.use(BodyParser())app.use(router)
app.use( Route("/helloworld", HelloController()) )Server(port: 3000, app.application).start()
```# Requirements
* Swift 2.1 or Later (includes Linux support)
* OS X 10.10 or Later# License
MIT