Simple aiohttp Server for both static and python/php file
Project description
Ahui-aiohttp-server
This is a simple http async server which extends python -m http.server
.
(WARN: It's not recommended for production environments, just use it in development or testing environments only!):
- Support print to http response directly (same as php's echo)
- Support async-await
- Support php, python
Install
pip install ahui-aiohttp-server
pip3 install ahui-aiohttp-server
Start server
$ tree .
./
app/
echo1.py
echo2.py
echo.php
return.py
js/
test.js
$ python -m ahui_aiohttp_server
$ python -m ahui_aiohttp_server --host 127.0.0.1 --port 5000
Access server
Access via echo server(php-like):
$ cat app/echo1.py
print('Hello World!')
$ curl http://127.0.0.1:5000/app/echo1.py
Hello World!
$ curl http://127.0.0.1:5000/js/test.js
<js content>
$ curl http://127.0.0.1:5000/app/echo.php
<js content>
If you want to get request data(such as: get, post, cookie, ...
, use aiohttp_handler(request)
instead:
$ cat app/echo2.py
def aiohttp_handler(request):
print(request.query) # use print
$ curl http://127.0.0.1:5000/app/echo2.py?var=value
{'var':'value'}
Access via normal aiohttp server:
$ cat app/return.py
from aiohttp import web
async def aiohttp_handler(request):
data = await request.post()
return web.Response(body=str(data)) # use return
$ curl http://127.0.0.1:5000/app/return.py?var=value - 'k1=v2'
{'k1':'v2'}
Access static file:
$ curl http://127.0.0.1:5000/js/test.js
<js content>
Required
- aiohttp
- python>=3.6
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for ahui_aiohttp_server-0.1.15.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a4b9bb9926f7fcd190cfb0ba7a1890740529a9030aa93d12a2bc6c0f2e40e86 |
|
MD5 | d105aedd92d3e8c633590a8a2c6b3a71 |
|
BLAKE2b-256 | ff425da069502e0b5c4d0d6b9f85e2dc44d00792d2f27e2ccd229a27fd618981 |
Close
Hashes for ahui_aiohttp_server-0.1.15-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f70ba55e3733afbedd824e949de5c4dc971b5c8774d6d0caac45fa91390ef1b |
|
MD5 | e6789d0e541f35f49ccbcb28cfb43857 |
|
BLAKE2b-256 | 2261c6f4445d536c2b10f28d9366e933b8856b447df625f8c887a55cc48d7721 |