snarkOS icon indicating copy to clipboard operation
snarkOS copied to clipboard

[Feature] Consider changing Records endpoints from GETs to POSTs and adding CORS.

Open fkrause98 opened this issue 2 years ago • 1 comments

🚀 Feature

  • Change the record related endpoints to post requests.
  • Add CORS support.
  • Change testnet3/records/ to a valid json array

Motivation

The record related endpoints from the snarkVM/rest/src/routes.rs files are these ones: ​

GET /testnet3/records/all
GET /testnet3/records/spent
GET /testnet3/records/unspent

​ They also receive a viewkey on the request’s body. Although this works when using curl, this prevents any browser from being able to call said endpoints as Javascript does not accept a body in a GET request. Like in this example, when trying to get records from the snarkOS-beacon: ​

let records_url = "http://127.0.0.1/testnet3/records/unspent" 
fetch(new Request(records_url), {method: 'GET', body: '"MyViewKey'})
// -> Uncaught (in promise) TypeError: Window.fetch: HEAD or GET Request cannot have a body.

​ Locally changing the endpoints to POSTs solves this.

Furthermore, when locally modifying said endpoints to POSTs, the browser returns CORS errors when doing requests.

fkrause98 avatar Sep 15 '22 19:09 fkrause98

See this related issue

facundoolano avatar Sep 16 '22 05:09 facundoolano

Closing as endpoints are now deprecated.

howardwu avatar Oct 09 '23 23:10 howardwu