Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streamlined REST API Methods then using the default endpoint generator #67

Open
waza-ari opened this issue Apr 26, 2024 · 7 comments
Open
Labels
Automatic Endpoint Related to automatic endpoint creation functionality bug Something isn't working enhancement New feature or request help wanted Extra attention is needed

Comments

@waza-ari
Copy link

Is your feature request related to a problem? Please describe.
First of all, thanks for your work and sorry for opening a million issues. This one is more of a debate I assume, as there is no "right" way of doing it. I do have the feeling that the current standard set of endpoints I suboptimal. Basically using the example:

router = crud_router(
    session=get_db,
    model=Ability,
    create_schema=AbilityCreateSchema,
    update_schema=AbilityUpdateSchema,
    path="/abilities",
    tags=["abilities"],
)

Yields these endpoints:

image

One example is: DELETE /api/v1/abilities/delete/{id} - we already know its deleting because of the HTTP verb - why does it need to be in the path again? The same applies to create (POST), update (PATCH) and get (GET) as well.

Describe the solution you'd like
I'd love to be able to configure something "cleaner" (although I'm fully aware that's very opinionated) like this:

image

The HTTP Verb here together with the endpoint is quite descriptive in itself (and obviously I should change the default endpoint description, but its just for the demo).

Its not possible to achieve this with customised endpoint names either, as it would yield a double slash even if setting the endpoint name for delete to an empty string.

@waza-ari waza-ari added the enhancement New feature or request label Apr 26, 2024
@igorbenav igorbenav added bug Something isn't working Automatic Endpoint Related to automatic endpoint creation functionality help wanted Extra attention is needed labels Apr 26, 2024
@igorbenav
Copy link
Owner

To be honest, I thought passing an empty string was working. Thanks for all the issues, by the way! Really great that you caught all of this stuff.

About the standard one, I don't have a formed opinion. I think if more people would comment here in favor, maybe we could change it to the cleaner option.

@JakNowy
Copy link
Contributor

JakNowy commented Apr 29, 2024

I had similar thoughts to @waza-ari, I think such simplification would be nice. Maybe we could even unify paginated and not paginated endpoints by introducing some optional pagination param, which makes it return all records if None or something like that.

@igorbenav
Copy link
Owner

This pagination part has been dealt with in #62, probably not the best option to make unpaginated a default endpoint (people might just add it blindly and then all of a sudden you allow users to get all your data at once). I think we could simplify the standard one though, go for the cleaner version.

Any of you guys want to do it?

@waza-ari
Copy link
Author

waza-ari commented May 4, 2024

Before saying yes, my question would be how to handle this change. If we change the default endpoint names and go for the "cleaner" version, that has the potential of breaking the code for other users relying on the current default behaviour. What would be your idea around that?

@igorbenav
Copy link
Owner

We add a warning in the release and in the docs and change version from 0.11.x to 0.12.0 to indicate breaking changes. Since we're at 0.y.z, breaking changes are acceptable (we're still figuring things out). We could also add a warning message when using EndpointCreator for the next couple of releases to indicate that things changed.

@JakNowy
Copy link
Contributor

JakNowy commented May 9, 2024

@waza-ari would be great if you could help with this!

I would go for GET PATCH and DELETE /hero/{id} and POST /hero/.
We may leave GET hero/get_multi/ and GET /hero/get_paginated/ as it is, while personally, I would love the get_paginated to become an optional feature of /get_multi/ controlled by some query parameters. Like optional page and page_size defaulting to None or whatever you find appropriate.

We can think about the warnings together once you issue a PR.

@igorbenav
Copy link
Owner

@waza-ari do you still plan to do this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Automatic Endpoint Related to automatic endpoint creation functionality bug Something isn't working enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants