snarkOS
snarkOS copied to clipboard
[Feature] Consider changing Records endpoints from GETs to POSTs and adding CORS.
🚀 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.
See this related issue
Closing as endpoints are now deprecated.