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

What do you mean with REST? #3

Closed
mro opened this issue Jun 15, 2016 · 8 comments
Closed

What do you mean with REST? #3

mro opened this issue Jun 15, 2016 · 8 comments

Comments

@mro
Copy link

mro commented Jun 15, 2016

I understand REST as

  1. use HTTP verbs
  2. use URIs like in DELETE /posts/Shsmbw or POST /posts/
  3. use HTTP status codes and reason phrases as in http://stackoverflow.com/questions/942951/rest-api-error-return-good-practices/34324179#34324179
@ArthurHoaro
Copy link
Member

Also being stateless

The client–server communication is further constrained by no client context being stored on the server between requests.

For the nice URIs, there is an open ticket, shaarli/Shaarli#508. I'm not sure we should include it here.
Using DELETE /?do=api&xx=posts&id=Shsmbw instead of DELETE /api/posts/Shsmbw is less clean, but not a very big deal.

@mro
Copy link
Author

mro commented Jun 15, 2016

is less clean, but not a very big deal

indeed, but if do likewise with the other two, it's not much REST left except marketing waffling.

@ArthurHoaro
Copy link
Member

Not really because in the end it's the exact same thing if routes are properly written.
I don't mind using clean URL for the API right now, but it needs to be well documented for nginx and eventually lighthttpd (Apache redirection can be done with .htaccess).

@virtualtam
Copy link
Member

Using DELETE /?do=api&xx=posts&id=Shsmbw instead of DELETE /api/posts/Shsmbw is less clean, but not a very big deal.

it's not much REST left except marketing waffling

Isn't REST itself already a marketing-swag-friendly term for designating a mere HTTP API dealing with JSON data?

use URIs like in DELETE /posts/Shsmbw or POST /posts/

Resource-centric routes help defining an API's endpoints, and can be assumed as a prerequisite, as this is how most API consumers will expect a RESTful service to be defined.

It is quite representative of the overall logic; for a given resource type, there should be:

  • one API endpoint (route)
  • one HTTP server/service view performing the actual action (depending on the HTTP verb, parameters and JSON payload)
  • one client function/method to emit queries altering this type of resource (and handling response statuses)

This involves enhancing Shaarli's router to handle such URLs, at least for the newly introduced API endpoints.

@ArthurHoaro
Copy link
Member

ArthurHoaro commented Jun 15, 2016

This involves enhancing Shaarli's router to handle such URLs, at least for the newly introduced API endpoints.

Depends how we handle redirection. For example, this won't require any work on the router, but requires more complex redirections (simplified):

/api/(\w+)/(\w+)\?(.*) --> ?do=api&request=$1&param=$2&$3

While this does:

/api/(.*) --> ?do=api&request=$1

Maybe a good way to have cleaner URIs for the API without being bother with web servers configurations is to do something like this:

DELETE ?do=api&q=/links/Shsmbw
POST     ?do=api&q=/links
GET       ?do=api&q=/links&limit=20

What do you think?

EDIT: actually, none requires work on the Router, but the way the API code will handle parameters.

@mro
Copy link
Author

mro commented Jun 15, 2016

rather DELETE api-v1.php?noun=links&id=Shsmbw – or is there a reason against a separate api.php that includes only the bare minimum of other code? E.g. no html render, no plugin stuff etc.)? &q= may be neat when it comes to searching.

@mro
Copy link
Author

mro commented Jun 16, 2016

let's first get #6 sorted. Will ninja-re-open later if appropriate.

@ArthurHoaro
Copy link
Member

I'd prefer to keep one entry point (index.php), to have in one place:

  • server settings initialization
  • plugin loading
  • configuration loading
  • router definition

It would avoid duplicating too much stuff.

Note that the template engine, RainTPL is loaded only if we need it.
Also, performance could be improved later with proper class autoloading.

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

No branches or pull requests

3 participants