An extremely lightweight and fast http server
Project description
FastHttpServer - Simple, Lightweight, and Fast HTTP Server
Overview
FastHttpServer is a pip package that offers a simple, lightweight, and fast HTTP server implemented in Python. This server provides a minimalistic solution for serving static content and handling basic HTTP requests. It is designed to be easy to set up, efficient in serving web content, and accessible as a pip-installable package.
Installation
To install FastHttpServer, use the following pip command:
pip install FastHttpServer
Also make sure the python 'socket' package is installed
Usage
- After installation, you can import and run the package:
from FastHttpServer import App
app = App()
or, if App is already reserved:
import FastHttpServer
app = FastHttpServer.App()
- Specify the routes of the server
use the app route wrapper and specify the route path. Make sure the proceeding function has a request parameter:
@app.route('/')
def index(request):
return '<h1>Success!</h1>'
by default the route only accepts GET requests if you want to accept POST or any other, specify in the methods parameter of the route wrapper:
@app.route('/', methods=['GET', 'POST'])
def index(request):
if request['method'] == 'GET':
return '<h1>Success</h1>'
else:
return {'message': 'Success!'}
It automatically detects html and json so no need to use json.dumps!
- Run the server:
First, run the server by calling the listen function of 'app':
app.listen()
By default, it runs on localhost port 3000 you can specify parameters to change both of those:
app.listen(PORT=8000, ADDRESS='127.0.0.1')
Open your web browser and navigate to http://localhost:3000 (or the custom port and address you specified). You should see a success or 404 indicating that the server is running.
Notes
-
This server is suitable for serving static content in development and testing environments. For production use, consider security and scalability aspects.
-
FastHttpServer is intentionally kept advanced and minimalistic.
-
Make sure the server listen is called last the routes below it wont work.
Feel free to use and contribute to FastHttpServer. Keep your web serving simple and enjoy the speed!
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
File details
Details for the file FastHttpServer-1.0.0.tar.gz.
File metadata
- Download URL: FastHttpServer-1.0.0.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
73cff677cbabb6d87860fa7d42121cd0f53e2317ed9de12b46ffef04727e5ea1
|
|
| MD5 |
4d9d8a144fe395a87047566f72b5b89a
|
|
| BLAKE2b-256 |
d7d8b5908530d03683dd30dc2019dbb0971994145861a829f8850bf52401b95c
|