Asita is a web application framework for python. It is designed to be easy to use and be more easy for javascript users to use python frameworks because it is based on express-js framework.
fromasitaimportApplication# creating application instanceapp=Application()
# callback when web server is readydeflisten_callback(error):
iferror:
raiseerrorprint(f"Server listening on port 1000.")
# listen the webserver on port (for instance port 1000)app.listen(1000, lambdaerror: listen_callback(error))
Application class
Methods
Name
Parameters
Description
all(path, callback)
path: string, callback: function
Routes an HTTP request, where all is the HTTP method such as GET, PUT, POST, OATCH, DELETE, HEAD
post(path, callback)
path: string, callback: function
Routes HTTP POST requests
get(path, callback)
path: string, callback: function
Routes HTTP GET requests
put(path, callback)
path: string, callback: function
Routes HTTP PUT requests
patch(path, callback)
path: string, callback: function
Routes HTTP PATCH requests
delete(path, callback)
path: string, callback: function
Routes HTTP DELETE requests
head(path, callback)
path: string, callback: function
Routes HTTP HEAD requests
define_asset(name, directory)
name: string, directory: string
Define the asset directory access
listen(port, callback)
port: integer, callback: function
start listening a port
Create a route
Exemple
# some awesome things check request and response methods :-)defhome(request, response):
pass# "/" is the default pathapp.all("/", lambdareq, res: home(req, res))