Giter Club home page Giter Club logo

sixi-web's Introduction

sixi-web CI

A simple web framework built for learning purpose.

Installation

pip install sixi-web

Usage

  1. Import the Sixi web api instance to route. If you’ve used Flask before, you'll find it easy.

    # app.py
    
    from sixi_web import API, Middleware
    
    app = API(templates_dir="templates", static_dir="static")
    
    
    @app.route("/")
    @app.route("/home")
    def index(req, resp):
        resp.text = "Hello world"
    
    
    @app.route("/about")
    def about(req, resp):
        resp.text = "A vegetable dog passing by."
    
    
    @app.route("/hello/{name}")
    def hello(req, resp, name):
        resp.text = f"Hello, {name}"
    
    
    @app.route("/add/{a:d}/{b:d}")
    def add(req, resp, a, b):
        result = int(a) + int(b)
        resp.text = f"{a} + {b} = {result}"
    
    
    @app.route("/todo")
    class TodoResource:
        def get(self, req, resp):
            resp.text = "Get a task"
    
        def post(self, req, resp):
            resp.text = "Create a task"
    
    
    @app.route("/html")
    def html(req, resp):
        resp.html = app.template("index.html", context=dict(title="hi", name="kada"))
    
    
    @app.route("/text")
    def text(req, resp):
        resp.text = "This is plain text"
    
    
    @app.route("/json")
    def json(req, resp):
        resp.json = dict(content="this is json")
    
    
    @app.error_handler(AttributeError)
    def attributeerror_handler(req, resp, e):
        resp.text = f"I got it, {e}"
    
    
    class PrintingMiddleware(Middleware):
        def process_request(self, req):
            print(f"request: {req}\n\n")
    
        def process_response(self, req, resp):
            print(f"response: {resp}\n\n")
    
    
    app.add_middleware(PrintingMiddleware)
  2. Run with any WSGI application server such as Gunicorn.

    gunicorn app:app

Roadmap

  • Request handler
  • Routing
  • Class based view
  • Unit tests
  • CI
  • Template support
  • Custom exception handler
  • Static files serving
  • Middleware
  • Custom response
  • Pypi
  • ORM
  • CD
  • Authentication
  • Demo app
  • Cli
  • Session and Cookies

Contributing

Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

sixi-web's People

Contributors

kadaliao avatar

Stargazers

 avatar  avatar

Watchers

 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.