Create a instance of the app, add a route then starting the server
app = App() app("/path"; method = GET) do request reponse = "hello" return response end start(app)
The handler function should take a
HTTP.Request and return a
If the return type isn't a
Response then it will be made into one by
create_response, you can
overload this function for any type from more control.
Routing and Query Parameters
Routes can be defined for multiple methods by passing an array
app(handler, "/path"; method = [GET, POST])
Routes can be parametrized by using the syntax
/:x. You can then access
the parameters in the handler with.
app("/route/:id", method = [GET, POST]) do request params = path_params(request) # Dict(:id => value) end
Specific routes will be matched first, in other words
"/route/1" will be matched before
Query parameters can be accessed in a similar way.
query = query_params(request)
Specific routes like
/path take priority over variable routes such as
To serve a single file from
By default the file will be served from the index, but you can specify a route with.
The MIME type will be infered from the extension, the supported MIME types can be found here. If the MIME type is unsuported it can be added to the global
After your handler is called if it's return type isn't a
Response it will be made into one by
create_response. You can overload
create_reponse for your specific type to have more control.
This is already defined for
AbstractDict, were the Content-Type header is set as
When instantiating the app you can pass any data structure you want to use for the session, by default this will be a
Dict. The session can then be accessed in the handler.
app("/path") do req session = app.session end
Dict isn't thread safe so this will likey change in the future to a differnt data structure.
For more examples see the
Some packages that you may find useful to pair wtih
- Octo.jl - a SQL Query DSL