Makes it quick to make HTTP servers
Project description
# lazyhttp
Drop in replacement for `http.server` with convenience methods added.
```python
import json
import http.server
import lazyhttp
class Handler(lazyhttp.Handler):
def req(self, task):
if '/create' in self.path or '/update' in self.path and \
self.has(task, 'id', 'text'):
TASKS[task['id']] = task
elif '/delete' in self.path and self.has(task, 'id'):
del TASKS[task['id']]
elif '/get' in self.path and self.has(task, 'id'):
self.json(TASKS[task['id']])
elif '/all' in self.path:
self.json(TASKS)
else:
self.err('Nothing to do')
if __name__ == '__main__':
lazyhttp.run(Handler)
```
Drop in replacement for `http.server` with convenience methods added.
```python
import json
import http.server
import lazyhttp
class Handler(lazyhttp.Handler):
def req(self, task):
if '/create' in self.path or '/update' in self.path and \
self.has(task, 'id', 'text'):
TASKS[task['id']] = task
elif '/delete' in self.path and self.has(task, 'id'):
del TASKS[task['id']]
elif '/get' in self.path and self.has(task, 'id'):
self.json(TASKS[task['id']])
elif '/all' in self.path:
self.json(TASKS)
else:
self.err('Nothing to do')
if __name__ == '__main__':
lazyhttp.run(Handler)
```
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
lazyhttp-0.0.1.tar.gz
(2.2 kB
view details)
File details
Details for the file lazyhttp-0.0.1.tar.gz
.
File metadata
- Download URL: lazyhttp-0.0.1.tar.gz
- Upload date:
- Size: 2.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 598b59bb6b159d10265bb2b594ba231a9230043cf8f1927d0d5c4f1ab63466e2 |
|
MD5 | 1dbeb127f5169ed6c3595106ddc3b231 |
|
BLAKE2b-256 | d58588e79a2d5503fedf7ac299ffd47bf70d70e62ee82683627b39170e21d416 |