Skip to content
This repository has been archived by the owner on Dec 22, 2022. It is now read-only.

Better way to register APIs #9

Open
uttamk opened this issue Jan 3, 2015 · 5 comments
Open

Better way to register APIs #9

uttamk opened this issue Jan 3, 2015 · 5 comments

Comments

@uttamk
Copy link
Contributor

uttamk commented Jan 3, 2015

Today the way to register APIs is to give it a leading name and version number which is kind of hardcoded.

api = Api(name='api', version='v1')

This translates to
api/v1/xxx
Both name and version should be optional.
Ideally it should be root accessible / without a version number

For example

api = Api(name='api', version='')  #/api/xxx
api = Api(name='', version='')      # /
api = Api(name='', version='v1')  # Nah maybe not
@raghuveerkancherla
Copy link
Contributor

api = Api(name='api/v1')

@kracekumar
Copy link
Contributor

+1 no version number.

api = Api()
api.register('users', MyUserResource)

...
So People in flask want to use decorators, so api should be flexible

@api.route('/users')
class MyUserResource:
....

or

@api.route('/users')
def user_resource():
.....

On Mon, Jan 5, 2015 at 10:40 AM, Raghu [email protected] wrote:

api = Api(name='api/v1')


Reply to this email directly or view it on GitHub
#9 (comment).

Regards
Kracekumar - +91-85530 29521
"Talk is cheap, show me the code" - Linus Torvalds

@raghuveerkancherla
Copy link
Contributor

I think we should keep the url routing part separate from the resources.
Resources implement CRUD without any assumptions about the delivery
mechanism (http). the decorator suggestion violates that.

On Mon, Jan 5, 2015 at 1:37 PM, Kracekumar Ramaraju <
[email protected]> wrote:

+1 no version number.

api = Api()
api.register('users', MyUserResource)

...
So People in flask want to use decorators, so api should be flexible

@api.route('/users')
class MyUserResource:
....

or

@api.route('/users')
def user_resource():
.....

On Mon, Jan 5, 2015 at 10:40 AM, Raghu [email protected] wrote:

api = Api(name='api/v1')


Reply to this email directly or view it on GitHub
#9 (comment).

Regards
Kracekumar - +91-85530 29521
"Talk is cheap, show me the code" - Linus Torvalds


Reply to this email directly or view it on GitHub
#9 (comment).

@kracekumar
Copy link
Contributor

Not sure. How current registration doesn't violate it.

api = Api(name='api', version='v1')
api.register_resource('foo', FooResource())

And decorator can be written as

@register(api_object, 'resource') as well

If you are using http, at some point bridge needs to exist. Calling a
method is one way and decorator is another way.

On Mon, Jan 5, 2015 at 1:42 PM, Raghu [email protected] wrote:

I think we should keep the url routing part separate from the resources.
Resources implement CRUD without any assumptions about the delivery
mechanism (http). the decorator suggestion violates that.

On Mon, Jan 5, 2015 at 1:37 PM, Kracekumar Ramaraju <
[email protected]> wrote:

+1 no version number.

api = Api()
api.register('users', MyUserResource)

...
So People in flask want to use decorators, so api should be flexible

@api.route('/users')
class MyUserResource:
....

or

@api.route('/users')
def user_resource():
.....

On Mon, Jan 5, 2015 at 10:40 AM, Raghu [email protected]
wrote:

api = Api(name='api/v1')


Reply to this email directly or view it on GitHub
#9 (comment).

Regards
Kracekumar - +91-85530 29521
"Talk is cheap, show me the code" - Linus Torvalds


Reply to this email directly or view it on GitHub
#9 (comment).


Reply to this email directly or view it on GitHub
#9 (comment).

Regards
Kracekumar - +91-85530 29521
"Talk is cheap, show me the code" - Linus Torvalds

@raghuveerkancherla
Copy link
Contributor

Yes but register_resource is at http_api level not at resource level.
Decorator on the other hand will have to be at Resource level

On Mon, Jan 5, 2015 at 2:01 PM, Kracekumar Ramaraju <
[email protected]> wrote:

Not sure. How current registration doesn't violate it.

api = Api(name='api', version='v1')
api.register_resource('foo', FooResource())

And decorator can be written as

@register(api_object, 'resource') as well

If you are using http, at some point bridge needs to exist. Calling a
method is one way and decorator is another way.

On Mon, Jan 5, 2015 at 1:42 PM, Raghu [email protected] wrote:

I think we should keep the url routing part separate from the resources.
Resources implement CRUD without any assumptions about the delivery
mechanism (http). the decorator suggestion violates that.

On Mon, Jan 5, 2015 at 1:37 PM, Kracekumar Ramaraju <
[email protected]> wrote:

+1 no version number.

api = Api()
api.register('users', MyUserResource)

...
So People in flask want to use decorators, so api should be flexible

@api.route('/users')
class MyUserResource:
....

or

@api.route('/users')
def user_resource():
.....

On Mon, Jan 5, 2015 at 10:40 AM, Raghu [email protected]
wrote:

api = Api(name='api/v1')


Reply to this email directly or view it on GitHub
#9 (comment).

Regards
Kracekumar - +91-85530 29521
"Talk is cheap, show me the code" - Linus Torvalds


Reply to this email directly or view it on GitHub
#9 (comment).


Reply to this email directly or view it on GitHub
#9 (comment).

Regards
Kracekumar - +91-85530 29521
"Talk is cheap, show me the code" - Linus Torvalds


Reply to this email directly or view it on GitHub
#9 (comment).

@kracekumar kracekumar added this to the Move Django Adapter out into its own repo milestone Jan 6, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants