REST API 中搜索的响应状态代码 [英] Response status code for searches in REST APIs

查看:22
本文介绍了REST API 中搜索的响应状态代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们有以下 API:

Suppose, we have the following API:

GET /api/guests/{id}

GET /api/guests?name=dummy

如果没有客人符合条件,我应该返回哪个状态代码?我的意思是没有名字叫dummy的客人.

Which status code should I return when there are no guests matching criteria? I mean no guests with name dummy.

应该是404204还是200,数组为空?

Should it be 404, 204 or 200 with an empty array?

推荐答案

我会用一个空数组返回 200...
或 204(无内容)

I would return 200 with an empty array...
Or a 204 (No Content)

404 是指找不到资源.在这种情况下,您的资源是客人的集合......存在.

A 404 is when a resource isn't found. Your resource in this case is the collection of guests... which exists.

这篇关于REST API 中搜索的响应状态代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆