The HTTP endpoints exposed by SurrealDB instances provide a simple way to interact with the database over a traditional RESTful interface. This includes selecting and modifying one or more records, executing custom SurrealQL queries, and managing SurrealML models.
The endpoints are designed to be simple and easy to use in stateless environments, making them ideal for lightweight applications where a persistent database connection is not required.
The most convenient way to access these endpoints is via SurrealDB’s Postman Collection. To do so, follow these steps:
GET /health, DEL /key/:table, etc.).ImportantEnsure that your URL is set correctly, if running locally, the URL should be
http://localhost:8000.By default, the URL is set to local. Start your server using thesurreal startcommand in the CLI or through Surrealist’s local database serving functionality, before querying the endpoints.
You can use the HTTP endpoints to perform the following actions:
| Function | Description |
|---|---|
GET /status | Checks whether the database web server is running |
GET /health | Checks the status of the database server and storage engine |
GET /version | Returns the version of the SurrealDB database server |
POST /import | Imports data into a specific Namespace and Database |
POST /export | Exports all data for a specific Namespace and Database |
POST /signup | Signs-up as a record user using a specific record access method |
POST /signin | Signs-in as a root, namespace, database, or record user |
GET /key/:table | Selects all records in a table from the database |
POST /key/:table | Creates a record in a table in the database |
PUT /key/:table | Updates all records in a table in the database |
PATCH /key/:table | Modifies all records in a table in the database |
DELETE /key/:table | Deletes all records in a table from the database |
GET /key/:table/:id | Selects the specific record from the database |
POST /key/:table/:id | Creates the specific record in the database |
PUT /key/:table/:id | Updates the specified record in the database |
PATCH /key/:table/:id | Modifies the specified record in the database |
DELETE /key/:table/:id | Deletes the specified record from the database |
POST /sql | Allows custom SurrealQL queries |
POST /graphql | Allows custom GraphQL queries |
POST /ml/import | Import a SurrealML model into a specific Namespace and Database |
GET /ml/export/:name/:version | Export a SurrealML model from a specific Namespace and Database |
/api/:namespace/:database/:endpoint | Create a custom API endpoint for any number of HTTP methods (GET, POST, etc.) |
GET /statusThis HTTP RESTful endpoint checks whether the database web server is running, returning a 200 status code.
Requestcurl -I http://localhost:8000/status
Sample outputHTTP/1.1 200 OK content-length: 0 vary: origin, access-control-request-method, access-control-request-headers access-control-allow-origin: * surreal-version: surrealdb-2.0.0+20240910.8f30ee08 server: SurrealDB x-request-id: 3dedcc96-4d8a-451e-b60d-4eaac14fa3f8 date: Wed, 11 Sep 2024 00:52:49 GMT
GET /healthThis HTTP RESTful endpoint checks whether the database server and storage engine are running.
The endpoint returns a 200 status code on success and a 500 status code on failure.
Requestcurl -I http://localhost:8000/health
Sample outputHTTP/1.1 200 OK content-length: 0 vary: origin, access-control-request-method, access-control-request-headers access-control-allow-origin: * surreal-version: surrealdb-2.0.0+20240910.8f30ee08 server: SurrealDB x-request-id: 24a1e675-af50-4676-b8ff-6eee18e9a077 date: Wed, 11 Sep 2024 00:53:22 GMT
GET /versionThis HTTP RESTful endpoint returns the version of the SurrealDB database server.
Requestcurl http://localhost:8000/version
Sample outputsurrealdb-2.0.0+20240910.8f30ee08
POST /importThis HTTP RESTful endpoint imports a set of SurrealQL queries into a specific Namespace and Database.
| Header | Description | ||
|---|---|---|---|
Authorization optional | Sets the root, namespace, or database authentication data | ||
Accept required | Sets the desired content-type of the response | ||
ns required | Sets the selected Namespace for queries. | ||
db required | Sets the selected Database for queries. |
| Header | Description | ||
|---|---|---|---|
Authorization optional | Sets the root, namespace, or database authentication data | ||
Accept required | Sets the desired content-type of the response | ||
Surreal-NS required | Sets the selected Namespace for queries. | ||
Surreal-DB required | Sets the selected Database for queries. |
NoteThe
-uin the example below is a shorthand used by curl to send an Authorization header.
Requestcurl -X POST -u "root:root" \ -H "ns: mynamespace" \ -H "db: mydatabase" \ -H "Accept: application/json" \ -d path/to/file.surql \ http://localhost:8000/import
Requestcurl -X POST -u "root:root" \ -H "Surreal-NS: mynamespace" \ -H "Surreal-DB: mydatabase" \ -H "Accept: application/json" \ -d path/to/file.surql \ http://localhost:8000/import
POST /exportThis HTTP RESTful endpoint exports all data for a specific Namespace and Database.
| Header | Description | ||
|---|---|---|---|
Authorization optional | Sets the root, namespace, or database authentication data | ||
ns required | Sets the selected Namespace for queries. | ||
db required | Sets the selected Database for queries. |
| Header | Description | ||
|---|---|---|---|
Authorization optional | Sets the root, namespace, or database authentication data | ||
Surreal-NS required | Sets the selected Namespace for queries. | ||
Surreal-DB required | Sets the selected Database for queries. |
| Arguments | Description |
|---|---|
| Whether only specific resources should be exported. When provided, only the resources specified will be exported. |
| Whether system users should be exported [possible values: true, false]. |
| Whether access methods (Record or JWT) should be exported [possible values: true, false] |
| Whether databases parameters should be exported [possible values: true, false] |
| Whether functions should be exported [possible values: true, false] |
| Whether analyzers should be exported [possible values: true, false] |
| Whether tables should be exported, optionally providing a list of tables |
| Whether SurrealKV versioned records should be exported [possible values: true, false] |
| Whether records should be exported [possible values: true, false] |
NoteThe
-uin the example below is a shorthand used by curl to send an Authorization header, while-oallows the output to be written to a file.
Requestcurl -X GET \ -u "root:root" \ -H "ns: mynamespace" \ -H "db: mydatabase" \ -H "Accept: application/json" \ -o path/to/file.surql \ http://localhost:8000/export
Requestcurl -X GET \ -u "root:root" \ -H "Surreal-NS: mynamespace" \ -H "Surreal-DB: mydatabase" \ -H "Accept: application/json" \ -o path/to/file.surql \ http://localhost:8000/export
Exporting specific parameterscurl -X POST \ -u "root:root" \ -H "Surreal-NS: mynamespace" \ -H "Surreal-DB: mydatabase" \ -H "Content-Type: application/json" \ -H "Accept: application/json" \ -o path/to/file.surql \ -d '{ "users": true, "accesses": false, "params": false, "functions": false, "analyzers": false, "versions": false, "tables": ["usersTable", "ordersTable"], "records": true }' \ http://localhost:8000/export
POST /signinMethod and URLPOST /signin
This HTTP RESTful endpoint is used to access an existing account inside the SurrealDB database server.
| Header | Description | ||
|---|---|---|---|
Accept required | Sets the desired content-type of the response |
| Data | Description | ||
|---|---|---|---|
ns required | The namespace to sign in to this is required FOR DB & RECORD users | ||
db required | The database to sign in to required for RECORD users | ||
ac required | The record access method to use for signing in. required for RECORD users | ||
user required | The username of the database user required for ROOT, NS & DB users | ||
pass required | The password of the database user required for ROOT, NS & DB users |
ImportantThe
acparameter is only required if you are signing in using an access method as a record user. For system users on the database, namespace, and root level, this parameter can be omitted.
Requestcurl -X POST -H "Accept: application/json" -d '{"ns":"test","db":"test","ac":"users","user":"john.doe","pass":"123456"}' http://localhost:8000/signin
Response{ "code": 200, "details": "Authentication succeeded", "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c" }
Requestcurl -X POST -H "Accept: application/json" -d '{"ns":"test","user":"john.doe","pass":"123456"}' http://localhost:8000/signin
Response{ "code": 200, "details": "Authentication succeeded", "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c" }
Requestcurl -X POST -H "Accept: application/json" -d '{"user":"john.doe","pass":"123456"}' http://localhost:8000/signin
Response{ "code": 200, "details": "Authentication succeeded", "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c" }
After you have defined the users permissions for the record user, you can use the POST /signin endpoint to sign in as a user.
Using the user credentials created add the following to the request body:
{ "ns": "test", "db": "test", "ac": "account", "email": "", "pass": "123456" }
POST /signupThis HTTP RESTful endpoint is used to create an account inside the SurrealDB database server.
| Header | Description | ||
|---|---|---|---|
Accept required | Sets the desired content-type of the response |
| Data | Description | ||
|---|---|---|---|
ns required | The namespace to sign up to. This data is | ||
db required | The database to sign up to. This data is | ||
access required | The record access method to use for signing up. This data is | ||
user required | The username of the database user. This data is | ||
pass required | The password of the database user. This data is |
Requestcurl -X POST -H "Accept: application/json" -d '{"ns":"test","db":"test","ac":"users","user":"john.doe","pass":"123456"}' http://localhost:8000/signup
Response{ "code": 200, "details": "Authentication succeeded", "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c" }
Before you sign up a new record user, you must first define a record access method for the user. To do so, follow these steps:
NoteYou can also define system users and user credentials using the
POST /sqlendpoint.
POST /sql endpoint in Postman.-- Enable authentication directly against a SurrealDB record DEFINE ACCESS account ON DATABASE TYPE RECORD SIGNUP ( CREATE user SET email = $email, pass = crypto::argon2::generate($pass) ) SIGNIN ( SELECT * FROM user WHERE email = $email AND crypto::argon2::compare(pass, $pass) ) DURATION FOR SESSION 24h ;
The above query defines a record access method called account that allows users to sign up and sign in. The access method also defines the session duration to be 24 hours.
Send to send the request to the SurrealDB database server.POST /signup endpoint in Postman.{ "ns": "test", "db": "test", "ac": "account", "email": "", "pass": "123456" }
Accept: application/jsontesttestaccountSend to send the request to the SurrealDB database server. You will get back a{ "code": 200, "details": "Authentication succeeded", "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpYXQiOjE3MDY2MTA4MDMsIm5iZiI6MTcwNjYxMDgwMywiZXhwIjoxNzA2Njk3MjAzLCJpc3MiOiJTdXJyZWFsREIiLCJOUyI6InRlc3QiLCJEQiI6InRlc3QiLCJBQyI6Imh1bWFuIiwiSUQiOiJ1c2VyOjZsOTl1OWI0bzVoa3h0NnY3c3NzIn0.3jR8PHgS8iLefZDuPHBFcdUFNfuB3OBNqQtqxLVVzxAIxVj1RAkD5rCEZHH2QaPV-D2zNwYO5Fh_a8jD1l_cqQ" }
GET /key/:tableThis HTTP RESTful endpoint selects all records in a specific table in the database.
| Header | Description | ||
|---|---|---|---|
Authorization optional | Sets the root, namespace, database, or record authentication data | ||
Accept required | Sets the desired content-type of the response | ||
ns required | Sets the selected Namespace for queries. | ||
db required | Sets the selected Database for queries. |
| Header | Description | ||
|---|---|---|---|
Authorization optional | Sets the root, namespace, database, or record authentication data | ||
Accept required | Sets the desired content-type of the response | ||
Surreal-NS required | Sets the selected Namespace for queries. | ||
Surreal-DB required | Sets the selected Database for queries. |
SELECT * FROM type::table($table);
POST /key/:tableThis HTTP RESTful endpoint creates a record in a specific table in the database.
NoteThis HTTP endpoint expects the HTTP body to be a JSON or SurrealQL
object.
| Header | Description | ||
|---|---|---|---|
Authorization optional | Sets the root, namespace, database, or record authentication data | ||
Accept required | Sets the desired content-type of the response | ||
ns required | Sets the selected Namespace for queries. | ||
db required | Sets the selected Database for queries. |
| Header | Description | ||
|---|---|---|---|
Authorization optional | Sets the root, namespace, database, or record authentication data | ||
Accept required | Sets the desired content-type of the response | ||
Surreal-NS required | Sets the selected Namespace for queries. | ||
Surreal-DB required | Sets the selected Database for queries. |
CREATE type::table($table) CONTENT $body;
PUT /key/:tableThis HTTP RESTful endpoint updates all records in a specific table in the database.
NoteThis HTTP endpoint expects the HTTP body to be a JSON or SurrealQL object.
| Header | Description | ||
|---|---|---|---|
Authorization optional | Sets the root, namespace, database, or record authentication data | ||
Accept required | Sets the desired content-type of the response | ||
ns required | Sets the selected Namespace for queries. | ||
db required | Sets the selected Database for queries. |
| Header | Description | ||
|---|---|---|---|
Authorization optional | Sets the root, namespace, database, or record authentication data | ||
Accept required | Sets the desired content-type of the response | ||
Surreal-NS required | Sets the selected Namespace for queries. | ||
Surreal-DB required | Sets the selected Database for queries. |
UPDATE type::table($table) CONTENT $body;
PATCH /key/:tableThis HTTP RESTful endpoint modifies all records in a specific table in the database.
NoteThis HTTP endpoint expects the HTTP body to be a JSON or SurrealQL object.
| Header | Description | ||
|---|---|---|---|
Authorization optional | Sets the root, namespace, database, or record authentication data | ||
Accept required | Sets the desired content-type of the response | ||
ns required | Sets the selected Namespace for queries. | ||
db required | Sets the selected Database for queries. |
| Header | Description | ||
|---|---|---|---|
Authorization optional | Sets the root, namespace, database, or record authentication data | ||
Accept required | Sets the desired content-type of the response | ||
Surreal-NS required | Sets the selected Namespace for queries. | ||
Surreal-DB required | Sets the selected Database for queries. |
UPDATE type::table($table) MERGE $body;
DELETE /key/:tableThis HTTP RESTful endpoint deletes all records from the specified table in the database.
| Header | Description | ||
|---|---|---|---|
Authorization optional | Sets the root, namespace, database, or record authentication data | ||
Accept required | Sets the desired content-type of the response | ||
ns required | Sets the selected Namespace for queries. | ||
db required | Sets the selected Database for queries. |
| Header | Description | ||
|---|---|---|---|
Authorization optional | Sets the root, namespace, database, or record authentication data | ||
Accept required | Sets the desired content-type of the response | ||
Surreal-NS required | Sets the selected Namespace for queries. | ||
Surreal-DB required | Sets the selected Database for queries. |
DELETE FROM type::table($table);
GET /key/:table/:idThis HTTP RESTful endpoint selects a specific record from the database.
| Header | Description | ||
|---|---|---|---|
Authorization optional | Sets the root, namespace, database, or record authentication data | ||
Accept required | Sets the desired content-type of the response | ||
ns required | Sets the selected Namespace for queries. | ||
db required | Sets the selected Database for queries. |
| Header | Description | ||
|---|---|---|---|
Authorization optional | Sets the root, namespace, database, or record authentication data | ||
Accept required | Sets the desired content-type of the response | ||
Surreal-NS required | Sets the selected Namespace for queries. | ||
Surreal-DB required | Sets the selected Database for queries. |
SELECT * FROM type::record($table, $id);
POST /key/:table/:idThis HTTP RESTful endpoint creates a specific record in a table in the database.
| Header | Description | ||
|---|---|---|---|
Authorization optional | Sets the root, namespace, database, or record authentication data | ||
Accept required | Sets the desired content-type of the response | ||
ns required | Sets the selected Namespace for queries. | ||
db required | Sets the selected Database for queries. |
| Header | Description | ||
|---|---|---|---|
Authorization optional | Sets the root, namespace, database, or record authentication data | ||
Accept required | Sets the desired content-type of the response | ||
Surreal-NS required | Sets the selected Namespace for queries. | ||
Surreal-DB required | Sets the selected Database for queries. |
CREATE type::record($table, $id) CONTENT $body;
PUT /key/:table/:idThis HTTP RESTful endpoint updates a specific record in a table in the database.
NoteThis HTTP endpoint expects the HTTP body to be a JSON or SurrealQL object.
| Header | Description | ||
|---|---|---|---|
Authorization optional | Sets the root, namespace, database, or record authentication data | ||
Accept required | Sets the desired content-type of the response | ||
ns required | Sets the selected Namespace for queries. | ||
db required | Sets the selected Database for queries. |
| Header | Description | ||
|---|---|---|---|
Authorization optional | Sets the root, namespace, database, or record authentication data | ||
Accept required | Sets the desired content-type of the response | ||
Surreal-NS required | Sets the selected Namespace for queries. | ||
Surreal-DB required | Sets the selected Database for queries. |
UPDATE type::record($table, $id) CONTENT $body;
PATCH /key/:table/:idThis HTTP RESTful endpoint modifies a specific record in a table in the database.
NoteThis HTTP endpoint expects the HTTP body to be a JSON or SurrealQL object.
| Header | Description | ||
|---|---|---|---|
Authorization optional | Sets the root, namespace, database, or record authentication data | ||
Accept required | Sets the desired content-type of the response | ||
ns required | Sets the selected Namespace for queries. | ||
db required | Sets the selected Database for queries. |
| Header | Description | ||
|---|---|---|---|
Authorization optional | Sets the root, namespace, database, or record authentication data | ||
Accept required | Sets the desired content-type of the response | ||
Surreal-NS required | Sets the selected Namespace for queries. | ||
Surreal-DB required | Sets the selected Database for queries. |
UPDATE type::record($table, $id) MERGE $body;
DELETE /key/:table/:idThis HTTP RESTful endpoint deletes a single specific record from the database.
| Header | Description | ||
|---|---|---|---|
Authorization optional | Sets the root, namespace, database, or record authentication data | ||
Accept required | Sets the desired content-type of the response | ||
ns required | Sets the selected Namespace for queries. | ||
db required | Sets the selected Database for queries. |
| Header | Description | ||
|---|---|---|---|
Authorization optional | Sets the root, namespace, database, or record authentication data | ||
Accept required | Sets the desired content-type of the response | ||
Surreal-NS required | Sets the selected Namespace for queries. | ||
Surreal-DB required | Sets the selected Database for queries. |
DELETE FROM type::record($table, $id);
POST /sqlThe SQL endpoint enables use of SurrealQL queries.
NoteThis HTTP endpoint expects the HTTP body to be a set of SurrealQL statements.
| Header | Description | ||
|---|---|---|---|
Authorization optional | Sets the root, namespace, database, or record authentication data | ||
Accept required | Sets the desired content-type of the response | ||
ns required | Sets the selected Namespace for queries. | ||
db required | Sets the selected Database for queries. |
| Header | Description | ||
|---|---|---|---|
Authorization optional | Sets the root, namespace, database, or record authentication data | ||
Accept required | Sets the desired content-type of the response | ||
Surreal-NS required | Sets the selected Namespace for queries. | ||
Surreal-DB required | Sets the selected Database for queries. |
Query parameters can be provided via URL query parameters. These parameters will securely replace any parameters that are present in the query. This practise is known as prepared statements or parameterised queries, and should be used whenever untrusted inputs are included in a query to prevent injection attacks.
NoteThe
-uin the example below is a shorthand used by curl to send an Authorization header.
Requestcurl -X POST -u "root:root" -H "ns: mynamespace" -H "db: mydatabase" -H "Accept: application/json" \ -d 'SELECT * FROM person WHERE age > $age' http://localhost:8000/sql?age=18
Requestcurl -X POST -u "root:root" -H "Surreal-NS: mynamespace" -H "Surreal-DB: mydatabase" -H "Accept: application/json" \ -d 'SELECT * FROM person WHERE age > $age' http://localhost:8000/sql?age=18
Requestcurl -X POST -H "Bearer: YourToken" -H "Surreal-NS: mynamespace" -H "Surreal-DB: mydatabase" -H "Accept: application/json" \ -d 'SELECT * FROM person WHERE age > $age' http://localhost:8000/sql?age=18
Response[ { "time": "14.357166ms", "status": "OK", "result": [ { "age": "23", "id": "person:6r7wif0uufrp22h0jr0o" "name": "Simon", }, { "age": "28", "id": "person:6r7wif0uufrp22h0jr0o" "name": "Marcus", }, ] } ]
POST /graphqlAvailable since: v2.0.0
The GraphQL endpoint enables use of GraphQL queries to interact with your data.
NoteThis HTTP endpoint expects the HTTP body to be a GraphQL query.
| Header | Description | ||
|---|---|---|---|
Authorization optional | Sets the root, namespace, database, or record authentication data | ||
Accept required | Sets the desired content-type of the response | ||
Surreal-NS required | Sets the selected Namespace for queries | ||
Surreal-DB required | Sets the selected Database for queries |
NoteThe
-uin the example below is a shorthand used by curl to send an Authorization header.
Requestcurl -X POST \ -u "root:root" \ -H "Surreal-NS: mynamespace" \ -H "Surreal-DB: mydatabase" \ -H "Accept: application/json" \ -d '{ "query": "{ person(filter: {age: {age_gt: 18}}) { id name age } }" }' \ http://localhost:8000/graphql
Response[ { "time": "14.357166ms", "status": "OK", "result": [ { "age": "23", "id": "person:6r7wif0uufrp22h0jr0o" "name": "Simon", }, { "age": "28", "id": "person:6r7wif0uufrp22h0jr0o" "name": "Marcus", }, ] } ]
POST /ml/importThis HTTP RESTful endpoint imports a SurrealML machine learning model into a specific Namespace and Database. It expects the file to be a SurrealML file packaged in the .surml file format. As machine learning files can be large, the endpoint expects a chunked HTTP request.
| Header | Description | ||
|---|---|---|---|
Authorization optional | Sets the root, namespace, database, or record authentication data | ||
ns required | Sets the selected Namespace for queries. | ||
db required | Sets the selected Database for queries. |
| Header | Description | ||
|---|---|---|---|
Authorization optional | Sets the root, namespace, database, or record authentication data | ||
Surreal-NS required | Sets the selected Namespace for queries. | ||
Surreal-DB required | Sets the selected Database for queries. |
NoteThe
-uin the example below is a shorthand used by curl to send an Authorization header.
Requestcurl -X POST \ -u "root:root" \ -H "ns: mynamespace" \ -H "db: mydatabase" \ -H "Accept: application/json" \ -d path/to/file.surml \ http://localhost:8000/ml/import
Requestcurl -X POST \ -u "root:root" \ -H "Surreal-NS: mynamespace" \ -H "Surreal-DB: mydatabase" \ -H "Accept: application/json" \ -d path/to/file.surml \ http://localhost:8000/ml/import
When using Python, the surreaml package can be used to upload the model with the following code:
from surrealml import SurMlFile url = "http://0.0.0.0:8000/ml/import" SurMlFile.upload("./linear_test.surml", url, 5)
GET /ml/export/:name/:versionThis HTTP RESTful endpoint exports a SurrealML machine learning model from a specific Namespace and Database. The output file with be a SurrealML file packaged in the .surml file format. As machine learning files can be large, the endpoint outputs a chunked HTTP response.
| Header | Description | ||
|---|---|---|---|
Authorization optional | Sets the root, namespace, or database authentication data | ||
ns required | Sets the selected Namespace for queries. | ||
db required | Sets the selected Database for queries. |
| Header | Description | ||
|---|---|---|---|
Authorization optional | Sets the root, namespace, or database authentication data | ||
Surreal-NS required | Sets the selected Namespace for queries. | ||
Surreal-DB required | Sets the selected Database for queries. |
NoteNote: The
-uin the example below is a shorthand used by curl to send an Authorization header, while-oallows the output to be written to a file.
Requestcurl -X GET \ -u "root:root" \ -H "ns: mynamespace" \ -H "db: mydatabase" \ -H "Accept: application/json" \ -o path/to/file.surml \ http://localhost:8000/ml/export/prediction/1.0.0
Requestcurl -X GET \ -u "root:root" \ -H "Surreal-NS: mynamespace" \ -H "Surreal-DB: mydatabase" \ -H "Accept: application/json" \ -o path/to/file.surml \ http://localhost:8000/ml/export/prediction/1.0.0
/api/:ns/:db/:endpointAvailable since: v2.2.0
CautionCurrently, this is an experimental feature as such, it may be subject to breaking changes and may present unidentified security issues. Do not rely on this feature in production applications. To enable this, set the
SURREAL_CAPS_ALLOW_EXPERIMENTALenvironment variable todefine_api.
A custom endpoint can be set using a DEFINE API statement. The possible HTTP methods (GET, PUT, etc.) are set using the statement itself. The path begins with /api, continues with the namespace and database, and ends with a custom endpoint that can include both static and dynamic path segments.
| Header | Description | ||
|---|---|---|---|
Authorization optional | Sets the root, namespace, or database authentication data | ||
Surreal-NS required | Sets the selected Namespace for queries. | ||
Surreal-DB required | Sets the selected Database for queries. |
Requestcurl http://localhost:8000/api/my_namespace/my_database/test_endpoint \ -H "Surreal-NS: ns" -H "Surreal-DB: db" \ -H "Accept: application/json"