Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/timatooth/yahs
Yet another HTTP Server in Python for creating basic REST APIs for trying out ideas.
https://github.com/timatooth/yahs
Last synced: about 1 month ago
JSON representation
Yet another HTTP Server in Python for creating basic REST APIs for trying out ideas.
- Host: GitHub
- URL: https://github.com/timatooth/yahs
- Owner: timatooth
- License: mit
- Created: 2015-06-12T05:06:43.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-01-29T10:02:43.000Z (almost 9 years ago)
- Last Synced: 2024-04-25T06:22:27.022Z (8 months ago)
- Language: Python
- Size: 20.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# YaHS Yet another HTTP Server
[![Build Status](https://travis-ci.org/timatooth/yahs.svg?branch=master)](https://travis-ci.org/timatooth/yahs)
HTTP server in a single Python file. Offers a Python decorator to register
functions for URL resources using regular expressions we all know and love.*
Handy for trying out your future REST api ideas.- Written in a single .py file
- No extra libraries needed
- HTTPS
- Uses Python ```logging``` module
- Self documenting API index at ```/``` when you use docstrings on the handlers.
- ```/yahs/reload``` reloads any module(s) that register any handlers to save stopping/starting server
- Basic Cross-Origin Resource Sharing (CORS) responses enabled for all request typesProbably not better than Django, Flask, Jersey or *other framework* :P
## Installation
Using pip
```pip install yahs```
Manual Install
```python setup.py install```
## Sample Usage
```
from yahs import Server, Response
@Server.handle('GET', '^/food$')
def get_food(request):
return "Hello there, here's some food!"@Server.handle('GET', r'/products/(?P[0-9]+)')
def get_product_by_id(request, product_id):
"""Gets a product by numeric id.
E.g /products/240
The regex named group/backreference 'product_id' will get added to the call when
someone requests the matching url pattern. It will have the value 240.
"""
response = Response()
response.body = "Yo here it is... Product: #{}
".format(product_id)
return responseserver = Server() # default port is 4321
server.start()
server.wait() # blocks the program from exiting early
```## License
MIT License
### Do-maybe-list
- Support class based Resource decorators with get, post, delete etc methods.**Results may vary depending on how much you know and love regular expressions.*