Skip to content

Proof of concept generating documentation for all endpoints

License

Notifications You must be signed in to change notification settings

neoneye/SwiftyServerRouter-Demo

Repository files navigation

SwiftyServerRouter-Demo

This is an example project for the SwiftyServerRouter framework, that shows how to generate documentation for all endpoints.

This is what the resulting documentation looks like

All the endpoints listed in a table

How to build the routes

There is a route for documentation: http://localhost:8181/docs

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

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()
    }
}

About

Proof of concept generating documentation for all endpoints

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published