Git Product home page Git Product logo

dream's Introduction

Dream

Dream is a hyper-minimal framework for creating WSGI apps, which leverages decoroute and WebOb to dispach and abstract requests. It’s particularly good for API type applications, as this is what it was originally written to support.

Features

Abstracted away from WSGI

You only have to deal with WebOb’s Request objects, and your functions return Response objects.

Nothing you don’t need

Very lightweight. No ORM. No admin page. Just URL routing and request/response objects.

Per-method endpoints

Decoroute has been extended to allow invoking different functions for the same URL based on the request method. This avoids ugly conditional code in your endpoint functions.

Conveniently namespaced

Common classes from WebOb & Decoroute are imported into the dream namespace — no need for anything other than import dream.

JSONResponse class

Since returning JSON is a common thing to do with Dream, there’s a Response subclass which will serialize it out for you. If you want a response intended for human consumption, there is also the clunkily-named HumanReadableJSONResponse.

Exception handling

Unhanded exceptions are caught and returned as 500 responses, with the exception reason in a JSON payload.

Endpoint introspection

Easily see the endpoints you’ve defined:

Crash course

Drop this into in my_app.py:

import dream

App = dream.App()

@App.expose('/greeting.json')
def hello_json(request):
    return dream.JSONResponse(body={'greeting': 'Hello, world!'})


@App.expose('/greeting.txt')
def hello_text(request):
    return dream.Response(body='Hello, world!',
                          headers={'Content-Type': 'text/plain'})

@App.expose('/greet/<person:.*>')
def hello_user(request, person):
    return dream.Response(body='Nice to meet you, %s' % person,
                          headers={'Content-Type': 'text/plain'})

Run it:

$ gunicorn my_app:App &
$ curl -i http://localhost:8080/greeting.json
$ curl -i http://localhost:8080/greeting.txt

Endpoint introspection

If you’d like to add an endpoint which returns known endpoints, add the following line:

dream.endpoints(App, '/endpoints.json')

dream's People

Contributors

ieure 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

Watchers

 avatar  avatar  avatar  avatar

Forkers

schuyler ieure

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.