restic / rest-server

Rest Server is a high performance HTTP server that implements restic's REST backend API.
BSD 2-Clause "Simplified" License
922 stars 138 forks source link

rest-server doesn't correctly implement REST API #238

Closed aawsome closed 1 year ago

aawsome commented 1 year ago

Output of rest-server --version

rest-server version rest-server 0.12.0 compiled with go1.20.3 on linux/amd64

How did you run rest-server exactly?

rest-server --noauth (but this issue is not related to authentication)

curl -X POST localhost:8000/test?create=true to initialize the repo.

curl localhost:8000/index/ or curl -H "Accept:application/vnd.x.restic.rest.v2" localhost:8000/index/; both return null (as the repo is empty)

What backend/server/service did you use to store the repository?

local

Expected behavior

We are running a list directory command on an empty repository. According to https://restic.readthedocs.io/en/latest/100_references.html#rest-backend, the output should be an empty JSON array, i.e. [].

Actual behavior

see above, output is null.

Steps to reproduce the behavior

see above.

Do you have any idea what may have caused this?

The way rest-server or Go serializes the response doesn't comply to the specification.

Do you have an idea how to solve the issue?

Either change rest-server to comply to the specification (e.g. see rclone which seems to implement the specification correctly) - or change the specification telling that null is also a valid response for an empty array.

Did rest-server help you today? Did it make you happy in any way?

No - today it only gave me trouble with https://github.com/rustic-rs/rustic, which does implement the REST API as specified ;-)

aawsome commented 1 year ago

This may be related to the fact that in go empty arrays can be specified as nil or []type{}. see also https://stackoverflow.com/questions/56200925/return-an-empty-array-instead-of-null-with-golang-for-json-return-with-gin

MichaelEischer commented 1 year ago

Returning [] seems more reasonable. And it saves 2 bytes ^^ .