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

查看:90
本文介绍了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.

应该是 404 204 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)

A 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天全站免登陆