API
Learn how to use Helium's JSON API
Authentication
Helium does not have a direct authentication system, but rather creates database connections on behalf of the user. As a result, Helium is capable of authenticating with any database using the MySQL protocol. A connection is uniquely identified by the username, password, host domain, and port. Currently, multiple users using the same connection works, but is unsupported behavior.
Once a connection has been established, an API key will be provided to the consumer. Every endpoint besides POST /api/v1/login
requires a X-API-Key
header whose value is the API key generated by the login endpoint.
Here's an example of using the API to authenticate a MySQL user called "bob" identified by the password "hunter2" located on the host "example.com":
Almost all other endpoints require an API key.
Sessions automatically expire after being out of use for a certain period of time (30 minutes by default). Attempting to use the API key after that will result in a 401 Unauthorized. Every API response using an API key will have a X-Session-Expiration
header whose value is the Unix time (milliseconds) at which the API key expires.
Login
POST
/api/v1/login
Attempts to establish a connection to a MySQL database. Returns an API key if successful.
Request Body
username
string
password
string
host
string
A domain name like google.com where the database is accessible from. Defaults to localhost.
port
number
Defaults to 3306, the default MySQL port
Ping
GET
/api/v1/ping
Tests the validity of the API specified by the X-API-Key header.
Returns: SessionPing
https://github.com/mattbdean/Helium/blob/master/common/api/session-ping.ts
Post-Authentication
Any endpoint listed here requires a valid X-API-Key
header to be specified in order to return a 200 OK response.
Fetch Schemas
GET
/api/v1/schemas
Returns a list of schema names accessible to the currently authenticated user. Equivalent to running SHOW SCHEMAS;
in the MySQL console.
Path Parameters
string
Fetch Tables
GET
/api/v1/schemas/:schema
Lists all tables in the given schema accessible to the current user. Returns: BaseTableName[]
https://github.com/mattbdean/Helium/blob/master/common/api/base-table-name.ts
Path Parameters
schema
string
The name of an accessible schema
Fetch Table Metadata
GET
/api/v1/schemas/:schema/:table
Gets metadata about a table, such as its headers, the total amount of rows, and constraints. Helium supports primary, foreign, and unique constraints as well as compound primary and foreign constraints.
Returns: TableMeta
https://github.com/mattbdean/Helium/blob/master/common/api/table-meta.ts
Path Parameters
schema
string
An accessible schema
table
string
A table that belongs to the schema
Fetch Column Data
GET
/api/v1/schemas/:schema/:table/data
Fetches data from a specific table. Supports filtering and sorting, and is paginated data.
Returns: PaginatedResponse<SqlRow>
https://github.com/mattbdean/Helium/blob/master/common/api/paginated-response.ts
Path Parameters
schema
string
table
string
Query Parameters
sort
string
The name of a column to by in ascending order. Prefixing the name with a hyphen reverses the sort direction.
limit
number
The maximum amount of items to return in a single page. Accepts values between 1 and 100, inclusive. Defaults to 25.
page
number
Page number. Accepts values greater than or equal to 1.
filters
array
A JSON array of Filter objects: https://github.com/mattbdean/Helium/blob/master/common/api/filter.ts
Pluck
GET
/api/v1/schemas/:schema/:table/pluck
Grabs all rows form all part tables belonging to the specified table. Assumes DataJoint creates part tables in the same schema as its master. The keys and values specified in the query are used to uniquely identify exactly one row from the master table. The keys of the query parameters should be column names, and the values should be specific values that exactly one column has. The most efficient way of specifying the selectors is by using only the primary keys of the master table.
Returns: TableInsert
https://github.com/mattbdean/Helium/blob/master/common/api/table-insert.ts
Path Parameters
schema
string
table
string
Insert Data
POST
/api/v1/schemas/:schema/data
Inserts data into a table. Multiple tables are allowed if one of the tables is a master table and the rest are part tables belonging to that master table. Accepts a TableInsert
in the HTTP request payload.
https://github.com/mattbdean/Helium/blob/master/common/api/table-insert.ts
Path Parameters
schema
string
Table Defaults
GET
/api/v1/schemas/:schema/:table/defaults
Fetches the default values for the given table at the time of the call. Every field will be resolved to a string, number, or null
. Any auto increment fields will be resolved to their next value and CURRENT_TIMESTAMP
will be resolved to a datetime string in the default MySQL format.
Path Parameters
schema
string
table
string
Last updated