https://github.com/neoneye/swiftyserverrouter-demo
Proof of concept generating documentation for all endpoints
https://github.com/neoneye/swiftyserverrouter-demo
perfect-server swift
Last synced: over 1 year ago
JSON representation
Proof of concept generating documentation for all endpoints
- Host: GitHub
- URL: https://github.com/neoneye/swiftyserverrouter-demo
- Owner: neoneye
- License: mit
- Created: 2018-06-21T16:50:00.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-23T14:57:08.000Z (about 8 years ago)
- Last Synced: 2025-03-21T09:35:21.551Z (over 1 year ago)
- Topics: perfect-server, swift
- Language: Swift
- Size: 14.6 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SwiftyServerRouter-Demo
This is an example project for the [SwiftyServerRouter](https://github.com/neoneye/SwiftyServerRouter) framework, that shows how to generate documentation for all endpoints.
## This is what the resulting documentation looks like

## How to build the routes
There is a route for documentation: http://localhost:8181/docs
```swift
do {
let handler = PerfectHTTPServer.HTTPHandler.staticFiles
let route = "/**"
let purpose = "Serve static files"
let data: [String:Any] = [
"allowResponseFilters": true
]
perfect_endpoint(method: .get, route: route, purpose: purpose, data: data, handler: handler)
perfect_endpoint(method: .head, route: route, purpose: purpose, data: data, handler: handler)
}
get("/healthcheck", EP_GetHealthcheck.self)
get("/docs", EP_GetEndpointDocumentation.self)
scope("/v1") {
get ("/debug", EP_Debug.self)
post ("/debug", EP_Debug.self)
put ("/debug", EP_Debug.self)
delete("/debug", EP_Debug.self)
}
```
## How to create an endpoint
```swift
import SwiftyServerRouter
class EP_GetHealthcheck: Endpoint {
required init() {}
let purpose = "Used for healthcheck functionality for monitors and load balancers"
func handler(context: HandlerContext) throws {
let _ = try? context.response.setBody(json: ["health": "ok"])
context.response.completed()
}
}
```