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.3.tar.gz
(2.5 kB
view hashes)