GlotPress / GlotPress

:earth_africa: :earth_americas: :earth_asia: GlotPress is a WordPress plugin to let you set up your own collaborative, web-based software translation tool.
https://wordpress.org/plugins/glotpress/
GNU General Public License v2.0
339 stars 123 forks source link

Leverage the WordPress REST API structure for API endpoints #338

Open ocean90 opened 8 years ago

ocean90 commented 8 years ago

The current API implementation is read-only and works a bit magically. It assumes that every route needs an API endpoint too, see https://github.com/GlotPress/GlotPress-WP/blob/ceba756f17b1075400611329a0c5e73cb671974d/gp-includes/router.php#L151. The route handler then loads a template with the api. suffix, see https://github.com/GlotPress/GlotPress-WP/blob/ceba756f17b1075400611329a0c5e73cb671974d/gp-includes/route.php#L199.

What this issue is about:

toolstack commented 8 years ago

It assumes that every route needs an API endpoint too

Might be more accurate to to say that every route can have an API endpoint too.

I agree the current API isn't the best, I've only been marginally following the REST API progress but there does seem to be some upheaval going on with it so I don't know if it's ready for us to move to yet.

Should we deprecate the old API for a version or two and then do a V2.0.0 release to remove it?

Do we need a write API?

Do we have to consider installs that may have created their own api templates and how to support them?

ocean90 commented 8 years ago

Should we deprecate the old API for a version or two and then do a V2.0.0 release to remove it?

I'm fine with that idea.

Do we have to consider installs that may have created their own api templates and how to support them?

The current API templates are just doing wp_json_encode() (or are using a fancy wrapper like gp_array_of_things_to_json or gp_array_of_array_of_things_to_json). I don't think that there are installs which are doing other stuff in a "template". Seriously, a template is the wrong way for this anyway.

Do we need a write API?

Well, the current write API is a POST request to a route. Having a REST API for all CRUD operations gives us the possibility to create single page web apps or even mobile apps (that's an interesting idea :)).

toolstack commented 8 years ago

The current API templates are just doing wp_json_encode() (or are using a fancy wrapper like gp_array_of_things_to_json or gp_array_of_array_of_things_to_json ). I don't think that there are installs which are doing other stuff in a "template". Seriously, a template is the wrong way for this anyway.

I agree and I suspect translate.w.org is probably the only site using the API in any significant way. As long as give some deprecation time I don't think it will be a problem, if someone pops up with a case where it is we can handle it then.

Do we need a write API?

Well, the current write API is a POST request to a route. Having a REST API for all CRUD operations gives us the possibility to create single page web apps or even mobile apps (that's an interesting idea :)).

Yep, just what we need, more work :wink:.

I'd say that this would be a nice to have, not a high priority item though.

ocean90 commented 8 years ago

I suspect translate.w.org is probably the only site using the API in any significant way.

Heh, I'd love to use the API in a "significant way". :smile: But it's poorly performing because of missing pagination. Most of the scripts are accessing the DB directly instead… There are also some sites which are using the /languages/$locale endpoints which we had to disable.

markoheijnen commented 8 years ago

Next time please inform me about it ;)

pbearne commented 8 years ago

love to be able to hook in from an installed plugin to be able to get translation stats to encourage users to help with translations may be part of the plugins list/details page

gedex commented 8 years ago

Is anyone actively working on this? I'd like to help on this to replace our https://github.com/Automattic/wc-lang-packs-server and use GP API instead.

ocean90 commented 8 years ago

@gedex Not yet. What are you looking for? I see some routes which are specific to translate.wordpress.org. These wouldn't be part of the default API.

gedex commented 8 years ago

I see some routes which are specific to translate.wordpress.org. These wouldn't be part of the default API.

@ocean90 Yeah, we'll build that as another GP plugin. Having GP endpoints based on WP REST API would be the first step before that.

ocean90 commented 7 years ago

Related request: Include GP_Locale Data when retrieving translation sets, can re-use the ?_embed behaviour of core.

maheshwaghmare commented 5 years ago

Is this feature still pending due to Backlog or backward compatibility or older users?

Any workaround for this feature?

toolstack commented 5 years ago

@maheshwaghmare still in backlog, no one has picked it up yet.