Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

What is the correct response to prevent "undefined" in custom endpoints?

default discord avatar
hoboharambe2 years ago
3

If I overwrite the default create endpoint using custom endpoints within a collection, and I get the newly created object ID {insertedId: id}, which return statement can help me prevent /api/collection/undefined? res.status(200).send("what should be here?")



What is the correct response to prevent "undefined" in custom endpoints?

  • default discord avatar
    dnl.krmr2 years ago

    Good morning, I currently don’t know your direct use case. If you need it directly, you should return the newly created id.



    Otherwise you should return HTTP Status code 201 created

    https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/201
  • default discord avatar
    hoboharambe2 years ago

    Thanks alot, the 201 status code helped and what I was looking for was const response = {message: "my message", doc: payload} and the payload includes the id and other document properties.

  • default discord avatar
    dnl.krmr2 years ago

    👍

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.