Cockpit: How to get single collection entries?

Created on 5 Jul 2018  路  5Comments  路  Source: agentejo/cockpit

Hi, how do I get single collection entries for single pages? Using a collection for case studies but don't understand how to get the content of a single entry based on slug for example.

// all entries
collections/get/Case?token=mytoken

// get single entry
how?

Most helpful comment

^ sure you could make a POST request, but why? It won't be cacheable and you'll have preflight overhead. Also it's semantically incorrect as you're not POSTing data you're GETting data. _I have argued with Artur about this before, I don't think he should put the snippet you've included here on his website because IMO it's bad practice_

All 5 comments

Hi @jesperlandberg,

I am not sure if I properly understood your requirement but it seems to me that you are looking for Singletons (only available in the @next branch). Singletons are useful for single entry points (e.g. Home, About us, etc) since they provide a single, translatable page.

If you still want/need to use collections, you'll have to get the first entry of the collection in the response data. E.g.

response.data.entries[0]

hi @ricardobrandao

To make it clearer. Imagine a blog. You would have a list with blog posts, and for each a "read more" link, which takes you to an article page. On this page I would like to retrieve only the data for this particular entry.

// all entries
collections/get/Case?token=mytoken

// get single entry
collections/get/Case?token=mytoken&filter[_id]=myentryid

// all entries
collections/get/Case?token=mytoken

// get single entry
collections/get/Case?token=mytoken

const options = {
    method: "POST",
    headers: { "content-type": "application/json" },
    body: JSON.stringify({
      filter: {
        _id: myentryid
      }
    })
  };

^ sure you could make a POST request, but why? It won't be cacheable and you'll have preflight overhead. Also it's semantically incorrect as you're not POSTing data you're GETting data. _I have argued with Artur about this before, I don't think he should put the snippet you've included here on his website because IMO it's bad practice_

Was this page helpful?
0 / 5 - 0 ratings

Related issues

desvu picture desvu  路  3Comments

flayks picture flayks  路  5Comments

pauloamgomes picture pauloamgomes  路  5Comments

victormoretti picture victormoretti  路  5Comments

tsimenis picture tsimenis  路  5Comments