|
||||||||
|
||||||||
back
2017/01/13 14:53
Kiss a rest api
I see a lot of things about python libs to help to make restful api, nowadays. Sure, hug is beautiful. Last year, I've made my own lib for that. But since some months, I use this KISS way, and I'm really happy with it : Server side, I create a HTTP POST endpoint (here with bottle):
Now, I can create a lot of serverside API (method which starts with 'API_'), example:
And client side, I call them easily, like this (here with angularjs, but likely the same with JS's fetch) :
And better, within 1 http request, I can call multiple api too, like this :
If I call one method, the result is in the "result" attribut of the response. If I call multiple, results are in a list in the "result" attribut of the response. If server side error, the traceback is in the "error" attribut of the response. It's very useful in a lot of cases, and it's hard to make simpler !? |
||||||||
|