Skip to main content

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.

Build Status Coverage Status

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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for fooster-web, version 0.4.0rc1
Filename, size File type Python version Upload date Hashes
Filename, size fooster_web-0.4.0rc1-py3-none-any.whl (24.9 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size fooster-web-0.4.0rc1.tar.gz (21.5 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page