Skip to content

Implement more RESTful routes - #119

Merged
Bluenix2 merged 6 commits into
python-discord:mainfrom
Bluenix2:main
Aug 6, 2021
Merged

Bluenix2 merged 6 commits into
python-discord:mainfrom
Bluenix2:main

Conversation

@Bluenix2

Copy link
Copy Markdown
Contributor

I am starting this pull request as a draft so that there's no conflicts between work. Resolves #115.

So I've thought about these a bit more, and it would probably be better to do the following..

  • GET /canvas/ Get the size; this should be the first one the user tries, that's why it's the simplest
  • GET /canvas/pixels Get all pixels
  • GET /canvas/pixels?x=0&y=0 Get a specific pixel
  • PUT Set a specific pixel, unsure which one is best
    • /canvas/pixels x, y and rgb is in the body
    • /canvas/pixels?x=0&y=0 only rgb in the body, but conforms better to how you get a pixel

The biggest issue with this second proposal is that now we have a "conflict" of GET /canvas/pixels and GET/canvas/pixels?x=0&y=0. We cannot have 2 documentation entries to outline this (if we use one that automatically generates documentation from the openapi spec).

Query string parameters must not be included in paths. They should be defined as query parameters instead.
This also means that it is impossible to have multiple paths that differ only in query string, such as:

GET /users?firstName=value&lastName=value
GET /users?role=value

This is because Swagger considers a unique operation as a combination of a path and the HTTP method, and additional parameters do not make the operation unique.

Of course it's not impossible, we can have one shared function. But this means we need to merge get_pixel and pixels doc-string. Leading to more confusion than UX we get.

That makes the first proposal conflict free, that said there may be improvements to be made?

  • GET /canvas/size
  • GET /canvas/
  • GET /canvas/pixels?x=0&y=0
  • PUT
    • /canvas/pixels
    • /canvas/pixels?x=0&y=0

@jb3

jb3 commented Jun 29, 2021 •

Copy link
Copy Markdown
Member

Feedback on endpoints:

  • Size should explicitly be in the endpoint, so something like GET /canvas/size.
  • Fetching an individual pixel should not use pixels plural imo, I'd rather keep it as GET /canvas/pixel?x=1&y=1 or put it in the URL parameters like GET /canvas/pixels/1/2 and document the order.
  • I don't like PUT with URL parameter and a body, it doesn't make sense. The document being created should be complete in the body, not partials in two different places.

(Personal thoughts, would like to hear from others)

@Bluenix2

Bluenix2 commented Jun 29, 2021 •

Copy link
Copy Markdown
Contributor Author
  • Fetching an individual pixel should not use pixels plural imo, I'd rather keep it as GET /canvas/pixel?x=1&y=1 or put it in the URL parameters like GET /canvas/pixels/1/2 and document the order.

Ah, interesting. The way I see it is that we're making a GET request to get the pixels, but we're using query parameters to narrow it down to one. That said, yes using GET /canvas/pixel?x=0&y=0 and GET /canvas/pixelS (plural) would remove that conflict I was talking about.

I don't like PUT with URL parameter and a body, it doesn't make sense. The document being created should be complete in the body, not partials in two different places.

Yeah the former would be better as PUT /canvas/pixel (singular).

@Bluenix2
Bluenix2 marked this pull request as draft June 29, 2021 14:26
@Bluenix2

Bluenix2 commented Jul 1, 2021

Copy link
Copy Markdown
Contributor Author

While this is being done, should moderation endpoints also get similar changes?

Bluenix2 added 2 commits July 21, 2021 01:09
They can now be considered more RESTful.
As opposed to having two different files, both routers are now in the
same file with one being submounted under the other.
@Bluenix2

Copy link
Copy Markdown
Contributor Author

I have now done some basic testing and squashed the commits so that this can be rebased.

@Bluenix2
Bluenix2 marked this pull request as ready for review July 20, 2021 23:19
@Bluenix2
Bluenix2 requested a review from ChrisLovering July 28, 2021 18:38
Comment thread pixels/endpoints/general.py Outdated
Bluenix2 and others added 2 commits August 7, 2021 00:35
Co-authored-by: ChrisJL <ChrisLovering@users.noreply.github.com>
@Bluenix2
Bluenix2 requested a review from ChrisLovering August 6, 2021 22:55
@Bluenix2
Bluenix2 enabled auto-merge August 6, 2021 23:18
@Bluenix2
Bluenix2 merged commit 0f89cf2 into python-discord:main Aug 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

More RESTful style endpoints

3 participants