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 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.

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.3rc9
Filename, size File type Python version Upload date Hashes
Filename, size fooster_web-0.3rc9-py3-none-any.whl (24.0 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size fooster-web-0.3rc9.tar.gz (20.3 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page