xiaohutai / jsonapi

[Bolt Extension] JSON API for Bolt CMS
https://market.bolt.cm/view/bolt/jsonapi
MIT License
55 stars 18 forks source link

Is it possible to return /contenttype/slug in the links property? #94

Closed zomars closed 5 years ago

zomars commented 5 years ago

This instead of the actual /contenttype/id?

Thanks in advance 🙏

xiaohutai commented 5 years ago

Short answer: no.

If you need the slug, you can read it from ['attributes']['slug']. So you can do your own routing in frontend for whatever you need.

Calling /json/{contenttype}/{slug} will still work with this extension. But calling by id is usually better, since the slug can change easier than the id.

zomars commented 5 years ago

I see. In my use case I'm doing a previous/next pagination using the links property, so I don't have the slug of the previous/next record at that time. I only have the slug for the current record. IDK if I'm explaining myself correctly.

xiaohutai commented 5 years ago

Yeah, I think that's outside the scope of this extension.

  1. You click on a next article link/button,
  2. then fetch the next article via API,
  3. then read the slug and set the value in the address bar.

So something like pushState, see https://developer.mozilla.org/en-US/docs/Web/API/History_API#Adding_and_modifying_history_entries

But if you're already using a framework, there might be something else available (usually this is coupled with routing).