Giter Site home page Giter Site logo

kobin's People

Contributors

c-bata avatar kuteken avatar kwatch avatar pyup-bot avatar takuan-osho avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

kobin's Issues

Before / After request hooks

I want to offer before/after request hooks like this:

from kobin import Kobin, request

app = Kobin()


@app.before_request
def before_request():
    print('Before request hook')

But it's just an idea. Your opinion are required.

Implement a static file server

In production, we use a nginx to return static files (ex. css, images, ... and so on).
But, in development, We want to use a static file server.

WebSocket support

Expect the types of routing arguments from type hints

In the following sample code, There is duplicate between types of routing and type hints because\w+ means str.

@app.route('^/user/(?P<name>\w+)/$')
def hello(name: str):
    return "Hello {}".format(name)

So I'd like to write like the following code.

@app.route('^/user/<name>/$')
def hello(name: str):
    return "Hello {}".format(name)

Error handling

  • HTTPError class
    • It only raise exception for now.
  • Error page
    • when content-type is text/json, return the error status and message in json style.
    • when content-type is text/html, return the error status and message in html.
    • others: only message.
  • http://postd.cc/choosing-an-http-status-code/

CONTENT_LENGTH exception if 'CONTENT_LENGTH' = ''

Summary

Expected Behavior

$ curl -d '{"key":"value"}' -X POST http://127.0.0.1:8000/user/
User Created
$ curl -X POST http://127.0.0.1:8000/user/
User Created

Actual Behavior

$ curl -d '{"key":"value"}' -X POST http://127.0.0.1:8000/user/
User Created
$ curl -X POST http://127.0.0.1:8000/user/
A server error occurred.  Please contact the administrator.

Environment

  • omit

Related Issue(Optional)

Type Hints for query parameters.

Summary

I want to exploit type hints for converting query parameters.

Description

IDEA 1

from kobin import Kobin, Response, Param

app = Kobin()

@app.route('/tasks/{task_id}')
def index(task_id: int, query_done: Param[bool]) -> Response:
    return Response('Hello World')

IDEA 2

from kobin import Kobin, Response, query_param

app = Kobin()

@app.route('/tasks/{task_id}')
@query_param('query_done')
def index(task_id: int, query_done: bool) -> Response:
    return Response('Hello World')

Modify URL Dispatcher

URL Dispatcher like matcha

A URL Dispatch with regex has high flexibility. But, In the most of the case, It isn't need.
So I suggest matcha like url dispatch with type hints.

It is a simple both the web framework developer and users.

@app.route('/post/{post_id}')
def post_detail(post_id: int):
    assert isinstance(post_id, int)

Converters like WebDispatch

@app.route('/post/{post_id}', converter=lambda id: Post.objects.get(id))
def post_detail(post: Post):
    template('post_detail.html', post=post)

Other references

Custom Request/Response class

Now, kobin always uses kobin.environs.request as a request. So we can use only LocalRequest.

Similarly, We can use only LocalResponse as a response.

However, I want to use a custom request/response like this:

import yaml
from kobin import Kobin
from kobin.environs import LocalRequest
from .environs import MyRequest, MyResponse

app = Kobin()
app.config['REQUEST_CLASS'] = MyRequest
app.config['RESPONSE_CLASS'] = MyResponse

NOTE: It's a just idea. Probably, there are better ways.

Remove run method and server adapter and static file serving and implement CLI

Remove static file serving

Because, it requires in development only. And it is not match new routing system.
Use wsgi-static-middleware

Remove run method

Because it is not compatible with wsgi middleware.

Add CLI

Because, it can offer previous function like this:

$ kobin myapp:app --server wsgiref --port 8000 --staticroot /static --staticdirs 

default:

  • server: wsgiref
  • port : 8080
  • staticroot : `app.config['STATIC_ROOT']
  • staticdirs : `app.config['STATICFILES_DIRS']

Progress

  • remove serving static files
  • remove server adapters
  • Add CLI

Add the topic about configurations on documents.

$ kobin-manager startproject myproject
$ python manage.py runserver  # Use conf.py on project root.
$ python manage.py runserver  --settings=settings.local
$ python manage.py runserver  --settings=settings.prod

Update for mypy 0.4

http://mypy-lang.blogspot.jp/2016/05/mypy-04-released.html

  • --fast-parser enables the new, faster parser (see above). This is still experimental but worth a try!
  • --disallow-untyped-defs generates errors for functions without type annotations. Consider using this if you tend to forget to annotate some functions.
  • --disallow-untyped-calls causes mypy to complain about calls to untyped functions. This is a boon for static typing purists, together with --disallow-untyped-defs :-)
  • --line-count-report DIRECTORY generates a report of annotated line counts.
  • --almost-silent behaves like --silent-imports, but it also reports every module that was silently ignored. This is useful for troubleshooting if mypy doesn’t seem to find all the code you are expecting.

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.