Pages detail API should allow fetching a page by path
See original GitHub issueCurrently the API endpoints provided by wagtail.api.v2.endpoints.PagesAPIEndpoint
do not provide the ability to fetch a Page by the page’s URL.
The docs regarding filtering pages makes it seem like a request such as
curl http://mysite.com/api/pages/?html_url=<some_url>
should work but instead the API returns:
{
"message": "query parameter is not an operation or a recognised field: html_url"
}
Would it be possible to support filtering on this field? Perhaps also making the detail view able to return the page by it’s path? i.e. allowing all of:
# filtering
curl http://mysite.com/api/pages/?html_url=<my_page_url>
# detail
curl http://mysite.com/api/pages/1
curl http://mysite.com/api/pages/my_page_path
If this is something that wagtail would like to add then I may be able to try submitting a PR.
The motivation for this feature is to make it easy for a frontend webapp to fetch pages and render them. It would be useful for SPA apps if they could integrate with a wagtail CMS backend by using the current pages URL to do a wagtail API request and use the JSON response to render a page using whatever framework the SPA is written with (react/angular/vue etc.).
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:5
Top GitHub Comments
It’s awesome to see this issue has had some attention. I just had a look at #4195 and i’m wondering if that view returning a redirect will result in unnecessary round trips for API clients who just want to GET a page by it’s path. I know for my usecase it likely will. Would a permanent redirect help? Could the view just use Django’s
reverse()
to skip the redirect alltogether? @kaedrohoAfter diving into the code a bit (i’m not familiar with it) I realize that achieving this through filtering probably isn’t feasible/practical for the API, but allowing individual pages to be retrieved by their path is possible.
i’ve hacked a little bit locally and this has some of my ideas in it:
This would allow API clients to do the following:
but there is no way to fetch the root page
So this isn’t the solution but hopefully others have some better ideas?