mike/app

Search:
Group by:
Source   Edit  

This is a fully typesafe version of the API. All responses should be done by returning like a normal function. For getting data, Context can be used by using context hooks is strongly encouraged

Types

AfterEachHandler = proc (ctx: Context; err: ref Exception) {.async, ...gcsafe.}
Handler that runs after every request. If there is an error then the exception will not be nil Source   Edit  
App = object
Entrypoint for a Mike application. All routes get registered to this Source   Edit  
BeforeEachHandler = AsyncHandler
Handler that runs before every request. Source   Edit  
ThreadStartHook = proc () {.closure.}
Hook that is called for each thread that is spawned when app starts. Source   Edit  

Procs

proc afterEach(mapp; handler: AfterEachHandler) {....raises: [], tags: [],
    forbids: [].}
Handler that runs after every request Source   Edit  
proc beforeEach(mapp; handler: BeforeEachHandler) {....raises: [], tags: [],
    forbids: [].}
Handler that runs before every request Source   Edit  
proc handle[E: Exception](mapp; err: typedesc[E];
                          handler: DispatchMethod[ref E, Context, Future[void]])
Adds an exception handler to the app. This handler is then called whenever the exception is raised when handling a route Source   Edit  
proc initApp(): App {....raises: [], tags: [], forbids: [].}
Creates a new Mike app. Source   Edit  
proc onStart(mapp; handler: ThreadStartHook) {....raises: [], tags: [], forbids: [].}
Add handler that only runs once when the server starts up Source   Edit  
proc onThreadStart(mapp; handler: ThreadStartHook) {....raises: [], tags: [],
    forbids: [].}
Add handler that runs when a worker thread is spawned Source   Edit  
proc run(app: var App; port: int = 8080; threads: Natural = 0;
         bindAddr: string = "0.0.0.0") {....gcsafe,
    raises: [Exception, OSError, ValueError, KeyError],
    tags: [RootEffect, WriteIOEffect, ReadIOEffect, TimeEffect], forbids: [].}
Starts the server, should be called after you have added all your routes Source   Edit  
proc runAsync(app: var App; port: int = 8080; threads: Natural = 0;
              bindAddr: string = "0.0.0.0"): Future[void] {....gcsafe,
    raises: [Exception, OSError, ResourceExhaustedError, ValueError],
    tags: [RootEffect], forbids: [].}
Starts the server in the background, useful for spawning a test server or integration with other async procs Source   Edit  

Templates

template afterConnect(mapp`gensym110; path`gensym110: static[string];
                      handler`gensym110: proc)
Source   Edit  
template afterDelete(mapp`gensym107; path`gensym107: static[string];
                     handler`gensym107: proc)
Source   Edit  
template afterGet(mapp`gensym104; path`gensym104: static[string];
                  handler`gensym104: proc)
Source   Edit  
template afterHead(mapp`gensym103; path`gensym103: static[string];
                   handler`gensym103: proc)
Source   Edit  
template afterOptions(mapp`gensym109; path`gensym109: static[string];
                      handler`gensym109: proc)
Source   Edit  
template afterPatch(mapp`gensym111; path`gensym111: static[string];
                    handler`gensym111: proc)
Source   Edit  
template afterPost(mapp`gensym105; path`gensym105: static[string];
                   handler`gensym105: proc)
Source   Edit  
template afterPut(mapp`gensym106; path`gensym106: static[string];
                  handler`gensym106: proc)
Source   Edit  
template afterTrace(mapp`gensym108; path`gensym108: static[string];
                    handler`gensym108: proc)
Source   Edit  
template beforeConnect(mapp`gensym92; path`gensym92: static[string];
                       handler`gensym92: proc)
Source   Edit  
template beforeDelete(mapp`gensym89; path`gensym89: static[string];
                      handler`gensym89: proc)
Source   Edit  
template beforeGet(mapp`gensym86; path`gensym86: static[string];
                   handler`gensym86: proc)
Source   Edit  
template beforeHead(mapp`gensym85; path`gensym85: static[string];
                    handler`gensym85: proc)
Source   Edit  
template beforeOptions(mapp`gensym91; path`gensym91: static[string];
                       handler`gensym91: proc)
Source   Edit  
template beforePatch(mapp`gensym93; path`gensym93: static[string];
                     handler`gensym93: proc)
Source   Edit  
template beforePost(mapp`gensym87; path`gensym87: static[string];
                    handler`gensym87: proc)
Source   Edit  
template beforePut(mapp`gensym88; path`gensym88: static[string];
                   handler`gensym88: proc)
Source   Edit  
template beforeTrace(mapp`gensym90; path`gensym90: static[string];
                     handler`gensym90: proc)
Source   Edit  
template connect(mapp`gensym101; path`gensym101: static[string];
                 handler`gensym101: proc)
Source   Edit  
template delete(mapp`gensym98; path`gensym98: static[string];
                handler`gensym98: proc)
Source   Edit  
template get(mapp`gensym95; path`gensym95: static[string];
             handler`gensym95: proc)
Source   Edit  
template head(mapp`gensym94; path`gensym94: static[string];
              handler`gensym94: proc)
Source   Edit  
template map(mapp; verbs: set[HttpMethod]; path: static[string];
             position: HandlerPos; handler: AsyncHandler)
Optimised version of map that doesn't wrap the proc since its already an AsyncHandler Source   Edit  
template map[P: proc](mapp; verbs: set[HttpMethod]; path: static[string];
                      position: HandlerPos; handler: P)
Low level function for adding a handler into the router. Handler gets transformed According to parameters/return Source   Edit  
template map[P: proc](mapp; verbs: set[HttpMethod]; path: static[string];
                      handler: P)
Like map(mapp, verbs, path, position, handler) except it defaults to a normal handler Source   Edit  
template options(mapp`gensym100; path`gensym100: static[string];
                 handler`gensym100: proc)
Source   Edit  
template patch(mapp`gensym102; path`gensym102: static[string];
               handler`gensym102: proc)
Source   Edit  
template post(mapp`gensym96; path`gensym96: static[string];
              handler`gensym96: proc)
Source   Edit  
template put(mapp`gensym97; path`gensym97: static[string];
             handler`gensym97: proc)
Source   Edit  
template trace(mapp`gensym99; path`gensym99: static[string];
               handler`gensym99: proc)
Source   Edit