Search code examples
httphttp-status-codes

HTTP status code for sending back just the meta-data not full data


I am looking for an appropriate HTTP status code that tells the receiver that just the meta-data is being sent, not the complete data.

For example, say you do an HTTP GET:

GET /foo?meta_data_only=yes

the server won't look up the complete data, just send some metadata back about the endpoint, for example. Is there an HTTP status code for the response that can represent this? I would guess it's in the 200s or 300s somewhere?


Solution

  • Since your metadata is being returned in the headers, I would send a status code of 204 No Content.

    https://httpstatuses.com/204

    The server has successfully fulfilled the request and that there is no additional content to send in the response payload body.

    Metadata in the response header fields refer to the target resource and its selected representation after the requested action was applied.

    This sounds exactly like what you’re looking for: a successful response that contains no body, and metadata in the headers that provide additional about the resource.

    Another thing worth noting is that it’s common practice to use the HTTP verb HEAD when you only want metadata. HEAD is very similar to GET, except that it specifies that you do not want a body back. For example if you do a HEAD to an image url, you will get a 204 No Content response and some metadata about the file such as Content-Type, Content-Size, maybe ETag, but you won’t be sent all of the file data. A lot of web servers (such as Nginx) support this behavior out of the box for static files. I would recommend that you stop using your querystring parameter, and instead implement HEAD versions of your endpoints. That would make the intention even more clear and intuitive.