2

I have developed simple posts endpoint and I do not know what to override and where to add status code. For example when some error happens I want to send 500 or when object created I want to send 201 instead of 200.

How and where to set status code in response of strapi?

Max
  • 375
  • 1
  • 4
  • 11

1 Answers1

10

Check out the strapi docs on responses, it uses a koa response object.
So you can do something like:

//controller
ctx.send({
    message: 'The content was created!'
}, 201);

You can apply your own logic and response by using custom endpoints or modifying the existing ones. These are some closely related examples of how to do that - answer1 , answer2.

Comment if you need more info

Eggcellentos
  • 1,570
  • 1
  • 18
  • 25