Giter VIP home page Giter VIP logo

python-simple-http-server's Introduction

python-simple-http-server

Discription

This is a simple http server, use MVC like design.

Support Python Version

Python 2.7 / 3.6+ (It should also work at 3.5, not test)

Why choose

  • Lightway.
  • Filter support.
  • Spring(Java) like request mapping.

How to use

Install

pip install simple_http_server

Write Controllers

from simple_http_server.server import request_map
from simple_http_server.http_server import Response


@request_map("/index")
def my_ctrl(parameters=None,
            json=None,
            **kargs  # This is required, for there are still other key arguments that will set to call this function
            ):

    return {"code": 0, "message": "success"}  # You can return a dictionary, a string or a `simple_http_server.simple_http_server.Response` object.


@request_map("/say_hello", method="GET")
def my_ctrl2(
        parameter=None,
        **kargs):
    return "<!DOCTYPE html><html><body>hello, %s</body></html>" % parameter["name"]


@request_map("/error")
def my_ctrl3(**kargs):
    return Response(status_code=500)


@request_map("/")
def my_ctrl4(response=None,
             **kargs):
    response.send_redirect("/index")

Start your server

# If you place the controllers method in the other files, you should import them here.

import simple_http_server.server as server
import my_test_ctrl


def main(*args):
    server.start()

if __name__ == "__main__":
    main()

python-simple-http-server's People

Contributors

keijack avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.