4

Is it possible to make a GET request to a JSON RPC API? I'm trying to do this using the random.org api (https://api.random.org/json-rpc/1/). It's functioning if I use a POST request but I need to make GET requests for all APIs that I'm using in the application I'm working on.

Here is the post request that is working:

function getNewThing(apiUrl) {

    data = {
        "jsonrpc": "2.0",
        "method": "generateIntegers",
        "params": {
            "apiKey": "key",
            "n": 1,
            "min": 0,
            "max": 1000000,
            "replacement": true,
            "base": 10
        },
        "id": 683489
    }

    // ajax call to the api
    return $.ajax({
        type: "POST",
        url: apiUrl,
        data: JSON.stringify(data),
        success: function(result) {

            console.log(result)
        },
        error: function(err) {
            console.log(err)
        }
    });
}

The reason I think this can be turned into a GET request is because this documentation implies it can be: http://www.jsonrpc.org/historical/json-rpc-over-http.html#encoded-parameters

I've tried to set up the URL the following ways with no luck:

With URL encoding for the params:

https://api.random.org/json-rpc/1/invoke?jsonrpc=2.0&method=generateIntegers&params=%7B%22apiKey%22%3A%20%229b6ed250-67fc-4afd-b60b-09c6076e5178%22%2C%22n%22%3A%201%2C%22min%22%3A%200%2C%22max%22%3A%201000000%2C%22replacement%22%3A%20true%2C%22base%22%3A%2010%7D&id=683489

Without:

'https://api.random.org/json-rpc/1/invoke?jsonrpc=2.0&method=generateIntegers&params={"apiKey": "9b6ed250-67fc-4afd-b60b-09c6076e5178","n": 1,"min": 0,"max": 1000000,"replacement": true,"base": 10}&id=683489'

What am I missing? Thanks in advance!

user3006927
  • 484
  • 4
  • 15

1 Answers1

0

Some kind folks from the NYJS meetup group helped me with an answer on this one. For anyone who happens find this question:

POST is the only option you'll have because GET is heavily discouraged. https://www.simple-is-better.org/json-rpc/transport_http.html#get-request http://www.jsonrpc.org/historical/json-rpc-over-http.html#http-header

For the random.org API, POST is the only option https://api.random.org/json-rpc/1/introduction

All invocations must be made via HTTP POST. In particular, HTTP GET is not supported.

With the note: "It's not really up to you and your implementation if a POST request can be processed additionally as a GET request - This is something a server would have to be setup in order to handle."

user3006927
  • 484
  • 4
  • 15