Git Product home page Git Product logo

daybed's Introduction

Daybed

A Web API providing validation and storage as a service

image

image

Highlights

  • Create REST APIs with no coding
  • Define dynamic models and relations
  • Validate and store records
  • Query and access data
  • Define role-based permissions and policies

Daybed is a minimalist, agnostic and generic REST API, built with bullet-proof technologies, such as CouchDB and Pyramid.

Notable features :

  • Permissions management
  • Geographical fields
  • Relationships between models
  • Pluggable database engine

Resources

License

Daybed is released under the BSD license - Copyright 2012-2014.

daybed's People

Contributors

almet avatar antoinecezar avatar arnaudbos avatar feth avatar leplatrem avatar magopian avatar n1k0 avatar natim avatar tarekziade avatar thomasg77 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

daybed's Issues

Rewrite functional tests

Lettuce features and scenariis may be a little bit of the track. I lack a good example of Web API testing.
However I really like the idea !

I wonder if we should actually be more readable in the scenarii file, for e.g :

When I send a bad model
When I send a incomplete model

And something like:

@step("When I send a (bad|incomplete) model")
def i_send_a_model(aspect):
    if aspect == 'bad':
         model = "{uierui:gjigjr}"
    elif aspect == "incomplete":
         model = '{"title" : "yeah"}'
    ...
    ...

I asked @stephane for a quick review :) Let's see!

Use JSON schema in definitions

After discussion with @AntoineCezar and debates in issue #9 it seems relevant to use JSON schema for model definitions, instead of our own formalism.

A basic investigation needs to address the following questions:

  • Should it replace or supplement the current definition formalism ?
  • Does it support current and planned field types ? #51 #33 #29
  • Is it extensible and simple enough to add custom notions ? #11
  • Could it address the need of defining and validating relationships between models ? #32
  • Is it redundant with SPORE ?

More generally, should JSON schema validation come as a Cornice extension or as internal Daybed mechanics ?

Registry for fields types

A way to register available fields types.

It should :

  • populate the list of supported values for the type field validator
  • add extra supported items in field definitions (e.g. choices, dateformat)
  • provide a validator for related fields of posted data (e.g. month<=12, abs(lat)<=90)

Geom field JSON validation error handling

  File "/home/mathieu/Code/daybed/src/daybed/validators.py", line 35, in schema_validator
    return validator(request, schema)
  File "/home/mathieu/Code/daybed/src/daybed/validators.py", line 20, in validator
    for field, error in error.asdict().items():
  File "/home/mathieu/Code/daybed/src/local/lib/python2.7/site-packages/colander/__init__.py", line 167, in asdict
    errors['.'.join(keyparts)] = '; '.join(interpolate(msgs))
TypeError: sequence item 0: expected string, exceptions.ValueError found

Remove tokens until proper ACL are implemented

The actual token system bring behaviors that does'nt look good to me.
When I POST data I excpect to get the full object with additionnal information like for exemple a "created_at".
In a POST based create definition I recive a token and have to follow a redirect to get the full object.
So unless there is a better way to pass tokens I suggest droping them for the moment.

Groups of fields with title and description

At model creation, it could be possible to define groups of fields:

SCHEMA = {
    name: "My super event",
    description: "",
    fields: [
        {   type: "string",
            name: "title",
            description: "blah",
        },
        {   name: "category",
            type: "enum",
            description: "blah",
            choices: ['sport', 'culture']
        },
        {   name: "street",
            type: "string",
        },
        {   name: "city",
            type: "string",
        },
    ],
    groups: [
        {  title: "Home",
           description:  "Your address helps us find you",
           fields: ["street", "city"]
        },
    ]
}

This would allow the UI to nicely layout the form for this model.

Since groups would be optional, they do not interfere with existing models, or those who don't need UI forms.

Records formatting

Accept HTTP directive may not be enough to format records.

For example, getting the records of a model which contain a geometry as JSON may have two formattings :

  • a basic JSON (as currently : [ {...}, {...} ])
  • a GeoJSON ( { "type": "FeatureCollection", "features": [{...}, {...}]), that integrates nicely in JS map widgets like Leaflet.

Both are valid JSON. We might need a ?format=XXX parameter to specify which layout it should have.

Add a POST method for definitions

I found myself trying to find a name for my definition even if I didn't needed one. That could be useful to have daybed deciding directly this kind of things for us. I like heroku which is choosing some names that "could" be real worlds, rather than using hashed of some sort.

Rework README

  • Draft a roadmap
  • Explain what it does not and will never do
  • Explicit missing parts supposed to become external projects (UI form builder, form & view, maps, mobile apps)

Documentation

The documentation is outdated.
We have to document everything.

Implement ACLs in the best possible way

(previous title was "remove the notion of token")

Suggested by @AntoineCezar

Daybed should be as standard as possible in terms of REST and CRUD.

If any ACL feature (see #8) has to be implemented, it may be relevant to implement it in a separated frontend rather than in daybed core.

Implement authentication using Persona

Browser ID is a really good idea to use daybed as as javascript UI backend.

Basically we can then use the email as the account id for models and data management.

Validation function at model field definition

Allow users to define their own validation function in the posted JSON model definition :

fields: [
        {
            type: "int",
            name: "age",
            description: "Your mother age",
            validation: "if (value < 15) { 
                                return 'Seems a bit young.';
                             }
                             else (value > 120) {
                                return 'Can't be so old.';
                             }
                             return null;",
        },

Most appropriate language seems to be Javascript (since JSON).

Javascript syntax must be checked during model definition.

Validation function should be executed on model post. In my opinion, server side (thus in python) :

http://renesd.blogspot.fr/search/label/shitjs

https://bitbucket.org/pypy/lang-js/src/de89ec32a7dc/js/javascript-interpreter.txt

http://code.google.com/p/pyv8/ : extra dep :(

Model relationships

We could envision a way to refer a model as a relationship :

Definition could look like:

{
"title": "Person",
"description": "An individual with a soul",
"fields": [
    {
        "name": "fullname",
        "type": "string",
    }, {
        "name": "brothers",
        "type": "many-to-many",
        "model": "Person"
    }

And an entry like :

{
    "name":  "Howard",
    "brothers": [54321, 9876]
}

Validating this entry would mean checking that provided brother ids exist.

How to manage records updates?

With this approach ?

  • Give UUID at record insertion (POST /model)
  • Hide records ids from public (GET /model)
  • Update a record with PUT /model/<UUID>

Means users should keep track of their uuids themselves, not fantastic.

Other idea (brainstorm)...

  • Provide password at record insertion (POST /model?lock=1234). If no password, record is public.
  • Show records ids in GET requests
  • Update records providing password

Actually, same approach could be applied to model definitions...

Will imply running daybed behind https...

PointType has no attribute name

POST invalid point data gives 500 error :


  File "/home/mathieu/Code/daybed/src/daybed/validators.py", line 35, in schema_validator
    return validator(request, schema)
  File "/home/mathieu/Code/daybed/src/daybed/validators.py", line 20, in validator
    for field, error in error.asdict().items():
  File "/home/mathieu/Code/daybed/src/local/lib/python2.7/site-packages/colander/__init__.py", line 165, in asdict
    keyname = exc._keyname()
  File "/home/mathieu/Code/daybed/src/local/lib/python2.7/site-packages/colander/__init__.py", line 153, in _keyname
    return str(self.node.name)
AttributeError: 'PointType' object has no attribute 'name'

Database creation is weird

When running tests, the "daybed" database should already be created otherwise an error will be thrown. This should be done automatically to avoid additional user hassle when users are getting started.

Implement PATCH on data items

PATCH allows us to only change some values inside an item, which is rather cool.

I want that :-) Less traffic, less headaches.

Add geometry field types

  • Point
  • Line
  • Polygon
  • Posted values will be coordinates list, like those stored in GeoJSON format
  • Will be rendered as GeoJSON individually
  • Collection of records will be rendered as GeoJSON only once issue #12 is implemented

Assertion error on header at data POST (waitress)

Request method: POST
Request URL: http://localhost:8000/data/mushroomspot
Request payload: {"mushroom":"tete","area":"[20.390625,7.536764322084078]"}

ERROR [waitress][Dummy-1] Exception when serving /data/mushroomspot
Traceback (most recent call last):
  File "env/local/lib/python2.7/site-packages/waitress/channel.py", line 329, in service
    task.service()
  File "env/local/lib/python2.7/site-packages/waitress/task.py", line 173, in service
    self.execute()
  File "env/local/lib/python2.7/site-packages/waitress/task.py", line 380, in execute
    app_iter = self.channel.server.application(env, start_response)
  File "env/local/lib/python2.7/site-packages/pyramid-1.4-py2.7.egg/pyramid/router.py", line 252, in __call__
    return response(request.environ, start_response)
  File "env/local/lib/python2.7/site-packages/WebOb-1.2.3-py2.7.egg/webob/response.py", line 1021, in __call__
    start_response(self.status, headerlist)
  File "env/local/lib/python2.7/site-packages/waitress/task.py", line 364, in start_response
    'Header value %r is not a string in %r' % (v, (k, v))
AssertionError: Header value u'http://localhost:8000/data/59fcf69f72069e8bf8d917a155001179' is not a string in ('location', u'http://localhost:8000/data/59fcf69f72069e8bf8d917a155001179')

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.