ipfs / kubo

An IPFS implementation in Go
https://docs.ipfs.tech/how-to/command-line-quick-start/
Other
15.97k stars 2.99k forks source link

Provide response body in the HTTP API for /api/v0/files/write endopint #7403

Open Gozala opened 4 years ago

Gozala commented 4 years ago

Unlike /api/v0/add endpoint that produces following response body on success:

{
  "Bytes": "<int64>",
  "Hash": "<string>",
  "Name": "<string>",
  "Size": "<string>"
}

Endpoint for /api/v0/files/write produces no results. Which happens to be at odds with js-ipfs files.write that returns {cid, size} pair.

There had being recent discussion about this mismatch between (See: https://github.com/ipfs/js-ipfs/pull/3055#issuecomment-636917239) HTTP-API and JS-IPFS API. While JS-IPFS could drop return value, I think it would be more useful to change HTTP-API to produce response body instead. I for one recall having to do two HTTP calls in the past to overcome this exact limitation.

lidel commented 4 years ago

@Stebalien is there a hard requirement that we don't return anything in response to /api/v0/files/write?

Given the fact more and more people use HTTP API (not just ipfs CLI), I would go as far as marking lack of CID in response as UX bug.

Would a PR adding response (cid, perhaps size?) be accepted? (js-ipfs is ok to go either way, as long go-ipfs decides)

Stebalien commented 4 years ago

I think we didn't return a CID so we could produce it lazily on demand. On the other hand, the current HTTP API isn't going to work for performance sensitive operations anyways. For that, we'll likely want an actual RPC API, with file handles and such.

TL;DR: Go ahead. However, we should probably avoid returning a CID if --flush=false is passed.