[PATCH 3/3] Create the API namespace

Bohuslav Kabrda bkabrda at redhat.com
Wed Jan 23 12:11:25 UTC 2013


----- Original Message -----
> This is the namespace that we will use to describe and expose the
> copr API.
> This commit introduce it, move some code from misc to the api_general
> and
> start with two API functions to list someone's copr and add a new
> one.
> 
> These two functions are documented in the /api/ (ie in the api.html
> template).
> ---
> 
> This is very simple for the moment and I a beginning of a CLI that
> can call this
> API and do something with it. That will be for a later commit.
> 
> One point though, I was not able to allow sending the data via post,
> I am afraid
> that this is due to the fact that I do not use forms. I might be
> better finally
> to just re-use the forms with csrf deactivated. Bonus, re-using the
> forms gives
> us input validation as well.
> 
> Thoughts on this?
> 

Could you be more elaborate on what the problem with post data was?
Reusing forms seems to be a good idea, although we have to be careful to pass the data in the format that forms expect.

<snip>
> + at api_ns.route('/add/<name>/<chroots>/',
> +    defaults={'repos':"", 'initial_pkgs':""})
> + at api_ns.route('/add/<name>/<chroots>/<repos>/',
> +    defaults={'initial_pkgs':None})
> + at api_ns.route('/add/<name>/<chroots>/<repos>/<initial_pkgs>/')
> + at login_required
> +def api_add_copr(name, chroots, repos="", initial_pkgs=""):
</snip>

Hmm, I really wouldn't do this. Let's take the time to do it via POST or GET params, not part of the url.

<snip>
> + at api_ns.route('/list/<username>/', methods=['GET'])
> +def api_list_copr(username):
</snip>

What I'd like to see here is copying the URLs from the web frontend part. E.g. listing all coprs should be just '/api/coprs/', listing coprs for a user '/coprs/owned/<username>/'. Also, I'd name the action for creation "new", not "add", as it corresponds with "copr_new" from coprs_ns, not "copr_add".

-- 
Regards,
Bohuslav "Slavek" Kabrda.


More information about the copr-devel mailing list