rest-api.tm 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. <TeXmacs|1.99.16>
  2. <project|rehash.tm>
  3. <style|tmmanual>
  4. <\body>
  5. <todo|Is this actually REST?>
  6. <todo|Will this actually be used?>
  7. <todo|Implement>
  8. <todo|maybe authentication>
  9. <todo|error codes are incomplete>
  10. <\explain>
  11. <samp|/v0/insert-mapping/INPUT_HASH/OUTPUT_HASH>
  12. <|explain>
  13. Using the POST method, a hash mapping can be inserted. The Content-Type
  14. of inserted data must be <samp|application/json>. Only UTF-8 has to be
  15. supported as character encoding. The JSON should have the following
  16. structure:
  17. <\verbatim>
  18. {
  19. \ \ "expiration-time": EXPIRATION_TIME,
  20. \ \ "anonymity-level": ANONYMITY_LEVEL,
  21. \ \ "content-priority": CONTENT_PRIORITY,
  22. \ \ "replication-level": REPLICATION_LEVEL,
  23. }
  24. </verbatim>
  25. Where <var|EXPIRATION_TIME> is in microseconds since the epoch,
  26. <var|ANONYMITY_LEVEL>, <var|CONTENT_PRIORITY> and <var|REPLICATION_LEVEL>
  27. are integers in the (inclusive) range
  28. <math|<around*|[|0,2<rsup|32>-1|]>>, and <var|INPUT_HASH> and
  29. <var|OUTPUT_HASH> are textual encodings of the hashes to insert.
  30. <paragraph|Error codes>Unless specified otherwise, no response body is
  31. defined yet, although future revisions of this API may include one.
  32. <\description>
  33. <item*|201 Created>The server has inserted the mapping into rehash.
  34. <item*|202 Accepted>The server will insert the mapping into rehash, but
  35. doesn't feel like waiting until this operation is completed.
  36. <item*|400 Bad Request>The request was not understood, e.g. due to an
  37. unsupported hash types.
  38. </description>
  39. </explain>
  40. <\explain>
  41. <samp|/v0/query/OUTPUT_HASH_TYPE/INPUT_HASH>
  42. <|explain>
  43. Using the POST method, one can search for mappings. The Content-Type of
  44. the request body must be <samp|application/json>. Only UTF-8 has to be
  45. supported as content encoding. The JSON should have the following
  46. structure:
  47. <\verbatim>
  48. {
  49. \ \ "anonymity-level": ANONYMITY_LEVEL,
  50. }
  51. </verbatim>
  52. The client must list UTF-8 as accepted character encoding, and
  53. <samp|application/json> as accepted Content-Type. The output is a stream
  54. of JSON objects:
  55. <\verbatim>
  56. {
  57. \ \ "expires": EXPIRATION_TIME,
  58. \ \ "output": OUTPUT_HASH,
  59. }
  60. </verbatim>
  61. Other fields may be defined in the future.
  62. As a convenience to the client, each object must be on a line of its own,
  63. where lines are separated by line feeds \<backslash\>n and/or carriage
  64. returns \<backslash\>r. This request can take infinite time to complete,
  65. and possibly have a theoretically infinite output. As such, the server
  66. should probably consider the result uncachable.
  67. <\description>
  68. <item*|200><todo|is this correct?>
  69. </description>
  70. </explain>
  71. <\explain>
  72. <samp|/v0/insert>
  73. <|explain>
  74. Using the POST method, a hash mapping can be inserted. The Content Type
  75. must be <samp|application/json>. Only UTF-8 has to be supported as
  76. content encoding. The JSON should have the following structure:
  77. <\verbatim>
  78. {
  79. \ \ "input": INPUT_HASH,
  80. \ \ "output: OUTPUT_HASH,
  81. \ \ "expiration-time": EXPIRATION_TIME
  82. \ \ "anonymity-level": ANONYMITY_LEVEL,
  83. \ \ "content-priority": CONTENT_PRIORITY,
  84. \ \ "replication-level": REPLICATION_LEVEL,
  85. }
  86. </verbatim>
  87. Where <var|EXPIRATION_TIME> is in microseconds since the epoch,
  88. <var|ANONYMITY_LEVEL>, <var|CONTENT_PRIORITY> and <var|REPLICATION_LEVEL>
  89. are integers in the (inclusive) range
  90. <math|<around*|[|0,2<rsup|32>-1|]>>, and <var|INPUT_HASH> and
  91. <var|OUTPUT_HASH> are textual encodings of the hashes to insert.
  92. </explain>
  93. <\explain>
  94. <samp|/v0/add?in=INPUT_HASH_TYPES&out=OUTPUT_HASH_TYPES>
  95. <|explain>
  96. Using the POST method, a file can be uploaded, to be inserted into GNUnet
  97. FS and rehash. The input and output hash types are specified in the
  98. comma-separated lists <var|INPUT_HASH_TYPES> and <var|OUTPUT_HASH_TYPES>.
  99. <paragraph|Optional parameters for query string>
  100. The server should define some reasonable defaults. It is recommended the
  101. client sets the User-Agent string appropriately (e.g. <samp|Guix
  102. substitute> or <samp|Guix build>) if not all parameters are set.
  103. <\description>
  104. <item*|<var|expiration-time>>See <samp|/v0/insert>
  105. <item*|<var|anonymity-level>>See <samp|/v0/insert>
  106. <item*|<var|content-priority>>See <samp|/v0/insert>
  107. <item*|<var|replication-level>>See <samp|/v0/insert>
  108. </description>
  109. <paragraph|Request headers>
  110. <\description>
  111. <item*|Content-Type>For uploading a single file, specify
  112. <samp|application/octet-stream>, and send this file as request body.
  113. <todo|how to upload directories? Perhaps multipart/x-nar or
  114. application/x-directory Or look at https://doc.ipfs.io/reference/http/api/#api-v0-add?>
  115. <todo|If on the same machine, perhaps pass a file descriptor?>
  116. <item*|Accept-Charset>Ask for UTF-8
  117. <item*|Accept>Ask for <samp|application/json>
  118. </description>
  119. <paragraph|Response headers>
  120. <\description>
  121. <item*|Content-Type><samp|application/json> (on success)
  122. The response has the following structure:
  123. <\verbatim>
  124. {
  125. \ \ "hashes": [ HASH_A, <text-dots> ]
  126. }
  127. </verbatim>
  128. Where <var|HASH_A> <text-dots> are hashes of type
  129. <var|INPUT_HASH_TYPES>, <var|OUTPUT_HASH_TYPES>. Other fields may be
  130. defined in the future.
  131. </description>
  132. <paragraph|Error codes>
  133. <\description>
  134. <item*|201 Created>The server has inserted the file into GNUnet FS and
  135. rehash.
  136. <item*|202 Accepted>The server will insert the file into GNUnet FS and
  137. and rehash, but doesn't feel like waiting until this is completed.
  138. <item*|400 Bad Request>This request was not understood, e.g. due to
  139. unknown hash types
  140. </description>
  141. <\remark>
  142. The kitchen sink <samp|/v0/download/HASH> is more general.
  143. </remark>
  144. </explain>
  145. <\explain>
  146. <samp|/v0/download/HASH>
  147. <|explain>
  148. Using the GET method, the client can try to download a file from its
  149. hash. Using the POST method, the client can make additional demands.
  150. <paragraph|Request body (for POST, <samp|application/json>)>
  151. <\verbatim>
  152. {
  153. \ \ "parallel-downloads": [{"url": url} <text-dots>],
  154. \ \ "dowload-anonymity": integer (\<less\> <math|2<rsup|32>>)
  155. \ \ "upload": {see <samp|v0/add>},
  156. \ \ "return?": true/false,
  157. \ \ "verify-certificates?": true/false,
  158. \ \ "input-hash-types": [INPUT_HASH_TYPE, <text-dots>],
  159. \ \ "output-hash-types": [OUTPUT_HASH_TYPE, <text-dots>],
  160. }
  161. </verbatim>
  162. The fields <var|parallel-downloads>, <var|upload>, <var|return?> and
  163. <var|verify-certificates?> are optional. <var|upload> defaults to false,
  164. <var|return?> to true and parallel-download to an empty list. No default
  165. is specified for <var|verify-certificates?>. <var|HASH> may be
  166. <samp|none> if <var|upload> is set and <var|input-hash-types> and
  167. <var|output-hash-types> is set.
  168. If <var|parallel-downloads> is set, it is suggested to the server that
  169. the resource may be available at the passed URLs. This can be useful if
  170. the file isn't well-represented in GNUnet FS and rehash yet. The server
  171. MUST NOT ignore URLs it doesn't support, but return a ??? instead.
  172. If <var|upload> is set, the server is requested to upload the downloaded
  173. request to GNUnet FS and rehash, using the hash types
  174. <var|INPUT_HASH_TYPE> <text-dots> and <var|OUTPUT_HASH_TYPE> <text-dots>.
  175. If <var|return?> is false, the server MUST NOT return the actual file.
  176. The option <var|verify-vertificates?> specifies whether certificates
  177. should be verified. Set this to false if you're a time-traveller or the
  178. servers aren't in the certificate store.
  179. <\remark>
  180. The passed URLs should support range requests, and should agree on the
  181. content. If not, be prepared for trouble.
  182. </remark>
  183. <\remark>
  184. This endpoint should support range requests.
  185. <todo|are range-requests allowed with POST method?>
  186. </remark>
  187. <\remark>
  188. Downloading will typically only work if a mapping from <var|HASH> to a
  189. GNUnet FS URI is known, unless <var|parallel-downloads> is seet
  190. appropriately.
  191. </remark>
  192. <\remark>
  193. File URLs like <samp|file:///gnu/store/???-package-version.tar.gz> can
  194. be passed with return?=false and <var|upload> set appopriately to
  195. upload a file from the local file system at the server. The server will
  196. likely restrict the use of such URLs though.
  197. </remark>
  198. <paragraph|Request headers>
  199. <\description>
  200. <item*|Accept>Include <samp|application/octet-stream> when downloading
  201. a file
  202. <item*|Accept-Charset>Include UTF-8 if <samp|application/json> is
  203. desired.
  204. <item*|Content-Type><samp|application/json> for POST.
  205. </description>
  206. <paragraph|Trailing response headers>
  207. <\description>
  208. <item*|X-Rehash-Hashes>When some hashes are computed, a comma-separated
  209. list of the textual representation of the hashes. Eventually, hashes of
  210. all types <var|INPUT_HASH_TYPE> <text-dots> and <var|OUTPUT_HASH_TYPE>
  211. <text-dots> should be computed. Some unsolicited hashes may be computed
  212. as well.
  213. <item*|X-Rehash-Bad-URL>Value: three-digit HTTP status code, space,
  214. some URL. The server tried to contact this URL, but failed. In case the
  215. of a status code \<less\> 100:
  216. 000 Evil: the server doesn't like this URL for its own whimsical
  217. reasons.
  218. 001 No such server: name resolution trouble
  219. 002 Connection rejected: trouble connecting to IP address (or similar)
  220. 003 Slow: rehash found this URL to be to slow
  221. <\remark>
  222. The server should try multiple URLs, and try old URLs again later.
  223. (In case the server temporarily had some trouble.)
  224. </remark>
  225. <item*|X-Rehash-Spinning>Value: <samp|unfortunately>, followed by a
  226. space, followed by a positive number of seconds, possibly followed by a
  227. space and a message to be defined in the future.
  228. The server tried to access all URLs for the desired data, but isn't
  229. finding anything anymore, and downloading over GNUnet isn't progressing
  230. nicely. As such, it seems the network is down or the file isn't
  231. well-represented in GNUnet or rehash. No further data is expected
  232. anytime soon. The client should consider to consider the download
  233. failed.
  234. Value: <samp|no>, possibly followed by a space and a message to be
  235. defined in the future. The server informs that the last
  236. <samp|X-Rehash-Spinning: unfortunately> doesn't apply anymore.
  237. </description>
  238. <paragraph|Response headers>
  239. <\description>
  240. <item*|Content-Type>On success, <samp|application/octet-stream> if
  241. requested
  242. </description>
  243. <paragraph|Status codes>
  244. <\description>
  245. <item*|200 Found>(Never encountered in current implementation). (Only
  246. for GET)
  247. This has the usual meaning.
  248. <item*|201 Created>(Never encountered in current implementation). (Only
  249. for POST)
  250. <todo|do we really need to include Location: header? (See HTTP specs)
  251. Ignored for now.>
  252. <item*|202 Accepted>The upload / download request is accepted. Whether
  253. it will make reasonable progress remains to be seen.
  254. <item*|400 Bad Request>Some parts of the request were not understood.
  255. E.g., unknown hash types, unsupported URLs
  256. </description>
  257. The resource searched for always exists, even though it might never be
  258. found.
  259. </explain>
  260. </body>
  261. <\initial>
  262. <\collection>
  263. <associate|chapter-nr|4>
  264. <associate|page-first|?>
  265. <associate|save-aux|false>
  266. <associate|section-nr|0>
  267. <associate|subsection-nr|4>
  268. </collection>
  269. </initial>