Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider return value when doing GET on non-existent table #165

Open
leondutoit opened this issue Jun 14, 2023 · 4 comments
Open

Consider return value when doing GET on non-existent table #165

leondutoit opened this issue Jun 14, 2023 · 4 comments

Comments

@leondutoit
Copy link
Collaborator

When a client does a GET on an endpoint which does not yet exist, but theoretically could, the API returns a 404, currently with a JSON message in the HTTP body. There has been a request to return [] instead.

A bit unclear what it should be, given that it is a 404, options:

  • no HTTP body at all
  • []
  • null
@f-krull
Copy link

f-krull commented Jun 14, 2023

@leondutoit
Copy link
Collaborator Author

The API currently functions:

  • similar to the way a filesystem does:
leoncd@leondutoit ~ % ls lol
ls: lol: No such file or directory
leoncd@leondutoit ~ % mkdir lol && touch lol/cat
leoncd@leondutoit ~ % ls lol
cat
leoncd@leondutoit ~ % rm lol/cat
leoncd@leondutoit ~ % ls lol
leoncd@leondutoit ~ %
  • similar to the way a database does:
leoncd@leondutoit ~ % psql -U tsd_backend_utv_user -d tsd_idp
psql (14.8 (Homebrew))
Type "help" for help.

tsd_idp=> select * from lol;
ERROR:  relation "lol" does not exist
LINE 1: select * from lol;
                      ^
tsd_idp=> create table lol(x int); insert into lol values (1);
CREATE TABLE
INSERT 0 1
tsd_idp=> select * from lol;
 x
---
 1
(1 row)

tsd_idp=> delete from lol;
DELETE 1
tsd_idp=> select * from lol;
 x
---
(0 rows)

The main difference is that mkidr, and create table are not implemented as separate API calls. One could imagine PUT /endpoint without a body would be an appropriate implementation, if needed.

Returning to the discussion, I think the current behaviour is fine, since it matches what you typically experience with other data storage interfaces. If we're going to change the behaviour of doing a GET /endpoint when the endpoint in question does not exist, then I favour returning 404 with no body at all, but not [].

@f-krull
Copy link

f-krull commented Jun 15, 2023

With 404, the body is fine as it is. No need to change.

@f-krull
Copy link

f-krull commented Jun 15, 2023

The main difference is that mkidr, and create table are not implemented as separate API calls.

Exactly. I guess the creation of the "container" works transparently under the hood to make it easier for clients to put stuff into it. It would be consistent to have the same transparency when listing the content of the container. Currently, every single implementation of a client has to handle the case "nothing there yet".

Anyway if 200 + [] comes with downsides, no big deal - let's keep it as it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants