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 multiprocessing
import fooster.web
sync = multiprocessing.Manager()
saved = sync.dict()
class Handler(fooster.web.HTTPHandler):
def do_get(self):
try:
return 200, saved[self.groups['path']]
except KeyError:
raise fooster.web.HTTPError(404)
def do_put(self):
saved[self.groups['path']] = self.request.body
return 200, 'Accepted'
def do_delete(self):
try:
del saved[self.groups['path']]
except KeyError:
raise fooster.web.HTTPError(404)
return 200, 'Deleted'
routes = { r'/(?P<path>.*)': Handler }
httpd = fooster.web.HTTPServer(('localhost', 8000), routes, sync=sync)
httpd.start()
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.3rc9.tar.gz
(20.3 kB
view hashes)
Built Distribution
Close
Hashes for fooster_web-0.3rc9-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db2bc23f1f901779d3cc23daeec90bfa85087a3261d2b0ad5ff4d5e7fb7eab46 |
|
MD5 | 25edd6206be36dd5e30900a7c6e160f7 |
|
BLAKE2b-256 | 773e3d9167a2bf76b5a536b50d2d90e16b35c93e41c44ee8b9f625f2275e7c56 |