a small, process-pooled web server utilizing the built-in Python socketserver
Project description
fooster-web
fooster-web is a small, process-pooled web server utilizing the built-in Python socketserver. It is designed from the ground up to be well structured, to conform to the HTTP/1.1 standard, and to allow for easy creation of a RESTful interface.
Usage
Below is a basic example that stores data via a PUT method and retrieves data via a GET method on any resource. If a resource has not been set, it returns a 404 error.
import fooster.db
import fooster.web
data = fooster.db.Database('data.db', ['path', 'body'])
class Handler(fooster.web.HTTPHandler):
def do_get(self):
try:
return 200, data[self.groups['path']].body
except KeyError:
raise fooster.web.HTTPError(404)
def do_put(self):
data[self.groups['path']] = data.Entry(self.request.body.decode())
return 200, 'Accepted\n'
def do_delete(self):
try:
del data[self.groups['path']]
except KeyError:
raise fooster.web.HTTPError(404)
return 200, 'Deleted\n'
routes = {r'/(?P<path>.*)': Handler}
if __name__ == '__main__':
import signal
httpd = fooster.web.HTTPServer(('localhost', 8000), routes)
httpd.start()
signal.signal(signal.SIGINT, lambda signum, frame: httpd.close())
httpd.join()
Examples and more information are available at the wiki.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fooster-web-0.4.0rc1.tar.gz
(21.5 kB
view hashes)
Built Distribution
Close
Hashes for fooster_web-0.4.0rc1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 461317225f7a9d416385d0c7b8c82470883b4a67bc99be921c6dbdb38e4df296 |
|
MD5 | 30914fba1c3d9a9251688ddea5b2e8a1 |
|
BLAKE2b-256 | f3ec47bb86ebac4a726c18f5a842214f431ccfe6e90e290ee8152e6138a5d51c |