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.2.tar.gz (4.0 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: FastHttpServer-1.0.2.tar.gz
  • Upload date:
  • Size: 4.0 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.2.tar.gz
Algorithm Hash digest
SHA256 ca3b8601ef6723ed8eff4a4dbb14d2705b01280b310aaaf94f6144ff330333ef
MD5 14ad46028e724753a40ea10308f7500d
BLAKE2b-256 f93fb2380d9bbf106051cb6997bd3008a0a77db6e6ccc613aa244ddab776a83c

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