Request

JSON-RPC

APIBlocks accepts HTTP/1 calls and follows JSON-RPC 2.0 specifications.

Request model

A JSON-RPC request looks like this:

{
    "jsonrpc": "2.0",
    "id": "15ab1a33-2991-4992-9eda-dca939f99709",
    "method": "apiblocks.OptimiseDNACodons",
    "params": {
        "dna": {
            "seq": "TGGCTTACGAGCTAC"
        },
        "organism": {
            "name": "e_coli"
        }
    }
}
jsonrpc

A version of JSON-RPC protocol. This must be set to "2.0"

id

An id of the request. You will also receive it back with the response object.

Warning

id can be any integer or string but we recommend you use universally unique identifiers (UUID). There a are standard libraries available to generate them for most languages.

method

Is a name of a method you want to call. This must have an apiblocks.* prefix followed by the name of a method from the APIBlocks Collection

params

You've guessed it! Parameters for the call. You can find parameters for each method in the corresponding page in the collection.

Tip

params can be omitted if method does not take any parameters as inputs.

Making a request

Send a POST request to https://api.apiblocks.dev/rpc. Don't forget to include a X-API-KEY header with your token.

import requests
import uuid

data = {
    "jsonrpc": "2.0",
    "id": str(uuid.uuid4()),
    "method": "apiblocks.OptimiseDNACodons",
    "params": {
        "dna": {
            "seq": "TGGCTTACGAGCTAC"
        },
        "organism": {
            "name": "e_coli"
        }
    }
}

headers = {
        "X-API-KEY": "{APIBLOCKS_TOKEN}"
}

response = requests.post(
        "https://api.apiblocks.dev/rpc",
        headers=headers,
        json=data
)
$ curl 'https://api.apiblocks.dev/rpc' \
-H 'X-API-KEY: $APIBLOCKS_TOKEN' \
-H 'Content-Type: application/json' \
--data '{
    "id": "12abdc79-14fa-4f17-bc69-50ce3926e4e0",
    "method": "apiblocks.OptimiseDNACodons",
    "params": {
      "method": "match_codon_usage",
      "dna": {
        "seq": "ATGTTAGAG"
      },
      "organism": {
        "name": "e_coli",
        "tax_id": 316407
      }
    }
  }'