Skip to main content

A package to create your python HTTP server with no effort

Project description

HTTPyServer

HTTPyServer is a package designed to help in the development of simple HTTP servers using Python. It lets you connect to your MongoDB database and handle requests binded to your DB.

HTTP Requests Handling

You can handle the HTTP requests after initialazing your Server instance.

The Server class takes 2 arguments:

  • address (str): The server address, formatted like "host:port"
  • root (Path): The absolute path of the root folder of your server (Which can be obtained with Path.cwd()).

This class has methods that will allow you to register some handlers (callbacks) that follow some specific conventions:

  • These methods are called by the Server.[Method] format, just like Server.GET, Server.POST, etc.

  • They all accept the following args:

    • path (str): The server path where this handler will be called.
    • handler ((RequestData) -> Basic_Response): The callback that will handle the upcoming requests.

Server.GET: An example

This method is used to register a GET handler that will be called when a GET request is received by the HTTP server. Example:

my_server = Server("localhost:8080", Path.cwd())

DB_Mongo("somemongodburi", "my_database_name") 
# Initializes your Mongo Database and allows all the handlers to work properly.

def home (request_data):
    res = Basic_GET_Response("main.html") # File in the same folder as this script
    res.send_file() # Sends the file contents to the response contents
    return res

def get_all_users (request_data):
    res = Basic_GET_Response("users-collection") # Collection of the MongoDB database
    res.send_db({}) # Sends a query to the collection and writes the response contents
    return res

my_server.GET("/", home)
my_server.GET("/users", get_all_users)

my_server.start()

MIT License

Copyright (c) 2025 Omar David Méndez Montiel

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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

httpyserver-1.0.1.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

httpyserver-1.0.1-py3-none-any.whl (17.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: httpyserver-1.0.1.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.5

File hashes

Hashes for httpyserver-1.0.1.tar.gz
Algorithm Hash digest
SHA256 7dffb85fe9938ade1a3b73c11dc125d04ec17b35fa64d5b49e06a8bf1f17d93f
MD5 b0325367256f63ae8f118f6ccd277475
BLAKE2b-256 96df525a21920af93701cf8cd4e1b40065eca2eacce459b9960cfa5061e8f4da

See more details on using hashes here.

File details

Details for the file httpyserver-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: httpyserver-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 17.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.5

File hashes

Hashes for httpyserver-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c12ba41acd2289ea1e5704ee1e085954cfe7de980f5fb22e14b02b60d3917d18
MD5 1f008a52be49610276c30293981cb883
BLAKE2b-256 00d82983a14b70d0e484e809d7849bdea47e3f205871ab48b9a9fe154ce07fa7

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