1

I've a content type called continent. Which we the name suggests contains all the information about each continents. Strapi already created API endpoints for me like

continents/:id

But I want to search the continent by it's name since the general user won't be able to search by id

I've created the endpoint

continents/:continent_name

I've also created custom controller following documentation

const { sanitizeEntity } = 
requiree('strapi-utils');

module.exports = {


async findOne(ctx) {
const { continent_name } = ctx.params;

const entity = await 
strapi.services.continent.findOne({ 
continent_name 
});
return sanitizeEntity(entity, { model: 
continents });

And also exposed the API to public But doesn't seem to anything Just returns error

How am I supposed to do it

1 Answer 1

1

For your use case, you don't need to extend the model controller. You can just pass the continent name as a query param . For example, your url could be something like base_url/continent?continent_name=Asia.

For the code mentioned in the question, there is an issue, the model name should be strapi.models.continent and not continents. Also in the first line requiree('strapi-utils'), you have an extra e in the require. I am assuming that was just a typo.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.