Code Samples
Here are a few simple snippets to get started
cURL
Initially login to get the temporary API key
curl -X 'POST'
'https://api.answr.space/api:auth/auth/login'
-H 'accept: application/json'
-H 'Content-Type: application/json'
-d '{ "email": "[email protected]", "password": "your_password" }'
{ "authToken": "eyJhbGciOiJBMjU2S1ciLCJlbm", "user": 2 }
Python
Initially login to get the temporary API key
import requests
headers = {
'accept': 'application/json',
# Already added when you pass json= but not when you pass data=
# 'Content-Type': 'application/json',
}
json_data = {
'email': '[email protected]',
'password': 'your_password',
}
response = requests.post('https://api.answr.space/api:auth/auth/login', headers=headers, json=json_data)
{ "authToken": "eyJhbGciOiJBMjU2S1ciLCJlbm", "user": 2 }
JavaScript
Initially login to get the temporary API key
fetch('https://api.answr.space/api:auth/auth/login', {
method: 'POST',
headers: {
'accept': 'application/json',
'Content-Type': 'application/json'
},
// body: '{\n "email": "[email protected]",\n "password": "your_password"\n}',
body: JSON.stringify({
'email': '[email protected]',
'password': 'your_password'
})
});
{ "authToken": "eyJhbGciOiJBMjU2S1ciLCJlbm", "user": 2 }
MATLAB
Initially login to get the temporary API key
%% Web Access using Data Import and Export API
uri = 'https://api.answr.space/api:auth/auth/login';
body = struct(
'email', '[email protected]',
'password', 'your_password'
);
options = weboptions(
'MediaType', 'application/json',
'HeaderFields', {'accept' 'application/json'}
);
response = webwrite(uri, body, options);
%% HTTP Interface
import matlab.net.*
import matlab.net.http.*
import matlab.net.http.io.*
header = [
HeaderField('accept', 'application/json')
HeaderField('Content-Type', 'application/json')
]';
uri = URI('https://api.answr.space/api:auth/auth/login');
body = JSONProvider(struct(
'email', '[email protected]',
'password', 'your_password'
));
response = RequestMessage('post', header, body).send(uri.EncodedURI);
{ "authToken": "eyJhbGciOiJBMjU2S1ciLCJlbm", "user": 2 }
R
Initially login to get the temporary API key
require(httr)
headers = c(
`accept` = 'application/json',
`Content-Type` = 'application/json'
)
data = '{\n "email": "[email protected]",\n "password": "your_password"\n}'
res <- httr::POST(url = 'https://api.answr.space/api:auth/auth/login', httr::add_headers(.headers=headers), body = data)
res <- content(res,"parsed")
{ "authToken": "eyJhbGciOiJBMjU2S1ciLCJlbm", "user": 2 }
Last updated