Skip to main content

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

  1. 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()
  1. 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!

  1. 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

FastHttpServer-1.0.1.tar.gz (3.8 kB view details)

Uploaded Source

File details

Details for the file FastHttpServer-1.0.1.tar.gz.

File metadata

  • Download URL: FastHttpServer-1.0.1.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

Hashes for FastHttpServer-1.0.1.tar.gz
Algorithm Hash digest
SHA256 c7da0247eeee09a97616eaeb6d22ff19dfbe4fe058f30d8b9645fbb1d1c9ca48
MD5 b2e1a30569a399ffc05f42774c382918
BLAKE2b-256 f8b57f81414e9c9b58663a50f22a2fe932bff0cb7d94c455826f9b2dbc4c014c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page