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
Built Distribution
File details
Details for the file fooster-web-0.4.0rc1.tar.gz
.
File metadata
- Download URL: fooster-web-0.4.0rc1.tar.gz
- Upload date:
- Size: 21.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca5a0c1c461f13a3a0c2fbc8f5df9f42242ea808c8e020f7a42815125d45c6b0 |
|
MD5 | 7c7ca2a9664dad0316c132e829f8f997 |
|
BLAKE2b-256 | 18c37a936410c2b2802c62fa20254ff8355950e5a8be1711a1d00a57c4a0acc4 |
File details
Details for the file fooster_web-0.4.0rc1-py3-none-any.whl
.
File metadata
- Download URL: fooster_web-0.4.0rc1-py3-none-any.whl
- Upload date:
- Size: 24.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 461317225f7a9d416385d0c7b8c82470883b4a67bc99be921c6dbdb38e4df296 |
|
MD5 | 30914fba1c3d9a9251688ddea5b2e8a1 |
|
BLAKE2b-256 | f3ec47bb86ebac4a726c18f5a842214f431ccfe6e90e290ee8152e6138a5d51c |