GithubHelp home page GithubHelp logo

ggl's Introduction

ggl

a tiny google app engine framework, to make your life even easier

installation

simply check out ggl.py and put it into your google app engine app. The ggl-framework just contains some tiny shortcuts. Besides these shortcuts you need to use the standard google app engine framework.

usage

routes

### main.py
from ggl import build_app, route

@route("/app")
def app_get(context):
    ### your code here
    context.render("templates/app.html")

app = build_app()

different HTTP-verbs

### main.py
from ggl import build_app, route

@route("/app")
def app_get(context):
    context.render("templates/app.html")

@route("/app", "post")
def app_post(context):
    context.render("templates/app.html")

@route("/app", "put")
def app_put(context):
    context.render("templates/app.html")

@route("/app", "delete")
def app_delete(context):
    context.render("templates/app.html")

app = build_app()

url-queries

### main.py
from ggl import build_app, route

### for /app?name=Marco&year=2013
### query strings will be provided via **kwargs
@route("/app")
def app_get(context, name, year):
    context.render("templates/app.html")

app = build_app()

returning json

### main.py
from ggl import build_app, route

@route("/app")
def app_get(context):
    context.render_json({"some key":"some value"})

app = build_app()

this will return the following json:

{"some key": "some value"}

force users to login with a google account

### main.py
from ggl import build_app, route, force_login

@route("/app")
@force_login
def app_get(context):
    """this function will only be accessed when the user 
    has successfully logged into his google account
    and given your application permission to use it"""
    context.render("templates/app.html")

app = build_app()

reverse - function lookups for redirects

### main.py
from ggl import build_app, route, get_url_for_func

@route("/newcall")
def newcall(context):
    """this function will redirect the request to the url 
    of the function 'app'"""
    context.redirect(get_url_for_func("app_get"))

@route("/app")
def app_get(context):
    ### ...

app = build_app()

how the backend works

Here is some standard google app engine code:

import webapp2

class MainHandler(webapp2.RequestHandler):
    def get(self):
        self.response.write('Hello world!')
    
    def post(self):
        name = self.response.get("name")
        self.response.write('Hello world!')

app = webapp2.WSGIApplication([('/', MainHandler)],
                              debug=True)

this will map to the following ggl-framework code:

from ggl import build_app, route

@route("/")
def app_get(context):
    context.write('Hello world!')

@route("/", "post")
def app_post(context, name):
    context.write('Hello world!')

app = build_app(debug=True)

For each route a "webapp2.RequestHandler" class will be created and receives one class function. This function exactly mapps to the get/post/put/delete function of the "webapp2.RequestHandler". Also, all query strings will me mapped to kwargs, so you don't have to go through the context/response-object to get them.

why I have done this

I have implemented quite a view applications with the flask framework and grew quite comfortable with its application design. With just a few lines of code you are up and running. I also like the google app engine project a lot, since it basically gives me a cloud instance, running python for free. However, I found the python framework in parts a bit too heavy and therefore implemented some short-cuts, which you can find in this project.

If you think I might have missed something or could do things even better please let me know about it and send me a github message/bug-report!

ggl's People

Contributors

m3o7 avatar

Watchers

 avatar  avatar

Forkers

digideskio

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.