How to use Plone.restapi

fetch(
        'http://localhost:8080/Plone/front-page', {
          headers: {
            'Accept': 'application/json', 
          }
        }
      )

For the API, I've cloned plone.restapi and have it up and running at localhost:8080 and I've checked it's functionality with Postman as well.

The problem seems to arise when I make the fetch request, it seems to catch this error in the console:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8080/Plone/front-page. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

And so fails to load any data from the API.

As a temporary fix, I've blocked Chrome from blocking these requests. Is there any proper fix for this issue?

Can help too! But as mentioned in the issue-tracker, there seems to a mixture of localhost:8080 , localhost:55001 and nohost used. Plus plone and Plone are used randomly. Any guides on moving forward with this?

You need to configure a proper CORS policy to allow JavaScript access. See an example here:


https://plonerestapi.readthedocs.io/en/latest/tusupload.html#cors-configuration

You will need to configure it in your buildout.cfg file, run the buildout and restart the instance.

Shouldn't this come preconfigured in the main repo itself? So that on install, it automatically does everything to setup the API properly?

No, I don't think this should be set by default.

I guess the reason for this inconsistency is quite simple. This may not be inconsistency at all. Though I haven't looked deeper to answer this.
But generally, localhost:8080 is being reserved for server-side applications ( Backend kinds of stuff).
And localhost:55001 is more commonly used in client-side rendering or applications (in the development phase, of course ). And people coming from JS might feel little confusing at first. I also felt the same when I was using Vuejs with Django.
I'm not an expert but if we just acknowledge this in the documentation, maybe we can remove this conflict.
And If we need to really change this for the sake of better understanding we should stick to localhost:8080.
It's just my point and we must decide this together before moving forward.
And maybe the inconsistency of Plone and plone is also due to this reason. People from JS ecosystem prefers CamelCasing and python have other conventions.
But api end point must have all small caps words like /plone/front-page.
I'm open to suggestion.
Any thoughts? @tisto @erral

1 Like

8080 is a common alternate port for HTTP[1] so that can be already taken (nginx or apache running in userspace on macOS is a good guess as to why), 55xxx is something I've commonly seen used for ZEO clients, but I'm unsure as to where the convention comes from as Apple liberally uses that range for its filesystem products[2]. No one has registered it on IANA; though, it is only listed as a private port[3]. In tests nohost is usually used. I'm assuming whomever writes documentation just pastes into the docs from whatever it is they are currently doing to get their example.

[1] https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml?search=8080
[2] https://support.apple.com/en-us/HT202944
[3] https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml?search=50001

The discrepancy of 8080 and 55001 in the documentation comes because part of the documentation is generated automatically during the test-phase and in this phase a Plone server is created and it listens on 55001

1 Like

What are we going to do about Plone is in http://localhost:8080/Plone/@components/navigation instead of plone?

Absolutely nothing :slight_smile: 'Plone' is the id used in the default Plone installation.
We could change the urls in the docs the say http://localhost:8080/Plone instead of http://localhost:55001/plone. Please file an issue for that at https://github.com/plone/plone.restapi/issues

We'd love to see some kind of beginners documentation, ie a small guide that outlines the steps to take to add plone.restapi to an existing Plone installation. That would to add it as an dependency in buildout or to the setup.py of your project; add the Generic Setup profile or use the Plone Control Panel; how to use Postman including the Accept headers etc.
It would be awesome if you would be willing to work on that! Please add an issue to https://github.com/plone/plone.restapi/issues and work on a feature branch, and I'd love to review this!

2 Likes

I would like to contribute as well! anyway I can🙂

1 Like

@tulikavijay
It would be great if you can help in polishing the Postman part

@jaroel
There is already an issue for this inconsistency [#285]
(https://github.com/plone/plone.restapi/issues/285).
I'll work to remove that first and then I'll work on adding installation guide and other tasks.

1 Like

I've opened an issue (https://github.com/plone/plone.restapi/issues/486) for adding installation instructions to the documentation. I'd like to work on it, so suggestions would help!

The documentation for using Postman to explore the API uses the Chrome extension, but it's mentioned in the extension that Chrome apps are being deprecated and use the native apps instead. So shouldn't the docs be updated using the native app for the tutorial?

Also I didn't get what you meant by how to use Postman, what improvements exactly are you suggesting for the doc (http://plonerestapi.readthedocs.io/en/latest/exploring.html) ?
@jaroel

@jaroel I can open an issue for Postman..Also I can add the section for using plone.restapi with Plone Control Panel.

@jaroel On Improvements on 'how to use Postman' section, do you mean adding an example with localhost:Plone and the accept headers? Also the screenshots are outdated.

I didn't know that there already are docs on Postman, that's a nice surprise!
Maybe you could update the screenshots and check if that bit of the docs is still correct?
A link to the Postman section from the index could help newcomers as well.

There's a link already in the introduction page. I think the docs and instructions provided are pretty much correct. The screenshots are actually up to date as it uses the Chrome Extension version of Postman.

But because of this, I suggest the doc should be using the native app version of Postman instead and also provide screenshots using it. @tulikavijay @jaroel

@tulikavijay Since I've mentioned this as an issue, I've already worked on it a bit as tisto mentioned it there. So I'll just update the doc to use native app version of Postman and change screenshots accordingly. I haven't made a branch yet for creating a new section for installation yet though, could help there!

Yeah sure go ahead! I have been using Postman for linux,that's why it looked different. I could take up the installation part and adding plone.reatapi as an add-on.