I'm designing a REST API which has a Banner
resource that's related to another two resources: Placeholder
and Page
.
While the relationship with Placeholder
can be null
, a Banner
must be related to a Page
. The business rules define that Pages are always created independently. Then, for new Banner
resources, the page does always exist and the page's id can be passed as a parameter. The same applies for the Placeholder
, although this could null
.
So, I decided that a Banner
resource can be also created independently (instead of a nested resource) as follows:
POST https://api.example.com/banners
{
"name": "banner's name",
"page": "PAGE_ID",
"placeholder": "PLACEHOLDER_ID",
... other parameters
}
What error code should be returned by the API when provided page
or placeholder
does not exist?
I'm returning a HTTP 404, but it feels odd. I thought about 409, but this doesn't look like a conflict.
PD: If I used a nested URL as POST /pages/<page_id>/banners
, the 404 makes sense for a non existent page
, but it still have the same problem for placeholder
.