Giter VIP home page Giter VIP logo

gaend's Introduction

gaend - Google App Engine Endpoints

Synopsis

This project converts a google.appengine.ext.ndb.Model into a HTTP endpoints. It provides validation, routing, documentation, and CRUD server endpoints. Its purpose is to act as a "DSL" for Google App Engine, allowing you to quickly write CRUD servers with just a Model.

Full Code Example

# app.yaml
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /.*
  script: gaend.main.APP
# main.py
from google.appengine.ext import ndb
from gaend.models import GaendFullMixin

class Alien(ndb.Model, GaendFullMixin):
    proboscis_count = ndb.IntegerProperty(default=1)
    kind = ndb.StringProperty(required=True, choices=["Grey", "Martian", "Hutt"])
    name = ndb.StringProperty(lambda s: len(s) >= 1 and len(s) <= 20)
    full_name = ndb.ComputedProperty(lambda self: self.name + " the " + self.kind)
> gcloud deploy app.yaml
...
Deployed service [modeling-agency] to [https://aliens-are-real.appspot.com]
...
> curl -H "Content-Type: application/json" \
  -d '{"kind": "Martian", "name": "Bob"}' \
  https://aliens-are-real.appspot.com/alien

{"key": "fsdafsdaf",
 "kind": "Martian",
 "proboscis_count": 1,
 "name": "Bob",
 "full_name": "Bob the Martian"}

Motivation

Sometimes your data is actually pretty simple.

  • You want to Create, Read, Update, and Destroy entities using REST endpoints.
  • You want to do validation every time an entity is written.
  • You want to have up to date documentation of your endpoints.

Sometimes, the ndb.Model class (Alien in the example) contains enough information to do all of the above bullet points. Why spend time writing boilerplate code that can be inferred? Are we programmers or are we programmers? Automate all the things.

Installation

> pip install gaend

Documentation

Gaend Read the Docs

Test

brew install entr

find ./gaend ./tests -name "*.py" -print | entr -drc python runner.py $GOOGLE_CLOUD_SDK

gaend's People

Contributors

samedhi avatar

Stargazers

 avatar

Watchers

 avatar  avatar

gaend's Issues

Task queue is based on callback hook

Basically, so every put using a gaend model always results in that model being added to the taskqueue (not just using the endpoints). The only question is if this is also done "within" the transaction? Otherwise, probably not that useful.

Lets override _get_kind() and put in duplicate checks?

override _get_kind() so that every class's kind is the lower() value of its class name. Will that help with detecting duplicates classes like class Hello and class HELLO that would end up with the same restful resource name?

Audit Logs

Probably should also be another project. I would like the ability to keep every previous version of of an entity in the datastore. Out of index, not directly visible, but I can see what the previous value of each entity was.

Google App Engine Soft Scan

GAE has no ability to do a scan of the database (this would require a lock). I have a solution that is probabilistically very likely to be able to scan every record. I think perhaps I should include this in another project, or maybe as a module under gaend?

How do we deal with nil/null/undefined in maps?

I think the rule should be that passing in nil always results in nil being written to the datastore. If you want to use the default value then don't include the key.

Or maybe it is the intersection of nil, default, and required? Should it automatically write the default in the event that it is also required and nil is passed in as a named value?

Thinking about it a bit more, I kind of feel that nil just shouldn't be allowed at all as a value to a property. nil should be indicated by the absence of a property, not by the fact that there is property that has been written with nil.

I should be able to specify the elasticsearch schema if desired.

Would be nice to be able to specify in the Model the elasticsearch schema. If no schema is provided elasticsearch will just default to its automatic mappings. However, if I need to it would be nice to actually specify them so that the ES indexes can be rebuilt from scratch at any time.

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.