feroult / yawp

Kotlin/Java API framework for Google Appengine
http://yawp.io
MIT License
132 stars 20 forks source link

Tutorial & Further Documentation #34

Closed danvass closed 8 years ago

danvass commented 8 years ago

Hello,

Could you create a short tutorial from setting up to developing a simple API using YAWP? In addition, is it possible to customise the GET/POST/etc. of a POJO or even disable specific ones to only allow GET for example?

Thanks, Daniel

feroult commented 8 years ago

Hi Daniel,

It is a great idea to have a short tutorial... I will work on it and let you know when its done.

About your 1st question, it is only possible to customize the default rest actions through the Hooks API:

public class PersonHook extends Hook<Person> {
    @Override
    public void beforeQuery(QueryBuilder<Person> q) {
    }
    (...)
}

I don't think it is ideal to have a lot of Hooks, because they can get messy very quick. I have plans to provide an extensible way to override default rest actions.

You can also add custom actions to Endpoints:

public class ActivatePersonAction extends Action<Person> {

    @PUT("active")
    public void activate(IdRef<Person> id) {
        Person person = id.fetch();
        person.setActive(true);
        yawp.save(person);
    }

}

Which creates a PUT /people/{id}/active http API.

For your 2nd question, the way to go is with the Shields API. It works like a white list firewall, since you've created a Shield for an Endpoint, all of it's actions (default and custom) get shielded (or disabled). Which means that you'll have to explicitly "open" each action. For instance:

public class PersonShield extends Shield<Person> {

    @Override
    public void show(IdRef<Person> id) {
        allow(isSomeUserWithAccessToThatPerson(id));
    }

}

There are convenient methods (always and defaults) to help you to override a shield behavior for all actions.

Hope it helps! Thanks.

danvass commented 8 years ago

Hi @feroult

Thanks for the detailed response. Seems like what I need. Once you have a short tutorial on making a basic API that uses the datastore I'll definitely move over to YAWP.

Thanks, Daniel

feroult commented 8 years ago

@DVassilev, I've prepared a short tutorial to bootstrap YAWP with a simple use case.

Please let me know things that you miss, so I can improve it. Probably it would be better to have a simple (but complete) app like a blog API or something.

Thanks!

[ ]s