slate/components/api/get.js

66 lines
1.8 KiB
JavaScript
Raw Normal View History

2021-03-22 21:17:42 +03:00
import * as React from "react";
import * as Constants from "~/common/constants";
import * as System from "~/components/system";
import CodeBlock from "~/components/system/CodeBlock";
import { css } from "@emotion/react";
2021-03-24 07:10:26 +03:00
const EXAMPLE_CODE_JS = (key) => `const response = await fetch('https://slate.host/api/v1/get', {
2021-03-22 21:17:42 +03:00
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Basic ${key}',
},
body: JSON.stringify({ data: {
private: false
}})
});
const json = await response.json();
console.log(json);`;
2021-03-24 07:10:26 +03:00
const EXAMPLE_CODE_PY = (key) => `import requests
2021-03-30 04:19:36 +03:00
import json as JSON
url = "https://slate.host/api/v1/get"
2021-03-24 07:10:26 +03:00
headers = {
2021-03-30 04:19:36 +03:00
"content-type": "application/json",
"Authorization": "SLA8d5a9c28-cb14-4886-b4ac-5575da2d90aaTE",
}
2021-03-24 07:10:26 +03:00
2021-03-30 04:19:36 +03:00
json = {"private": "false"}
2021-03-24 07:10:26 +03:00
2021-03-30 04:19:36 +03:00
get = requests.post(url, headers=headers, json=json)
2021-03-24 07:10:26 +03:00
2021-03-30 04:19:36 +03:00
print(JSON.dumps(get.json(), indent=2))`;
2021-03-24 07:10:26 +03:00
2021-03-30 04:19:36 +03:00
export default class APIDocsGet extends React.Component {
render() {
let APIKey = this.props.APIKey;
let language = this.props.language;
let code = {
javascript: EXAMPLE_CODE_JS(APIKey),
python: EXAMPLE_CODE_PY(APIKey),
};
2021-03-24 07:10:26 +03:00
return (
<React.Fragment>
<System.DescriptionGroup
2021-03-30 04:19:36 +03:00
style={{ maxWidth: 640, marginTop: 64 }}
2021-03-24 07:10:26 +03:00
label="Get all slates"
2021-03-30 04:19:36 +03:00
description="This API request returns all of your slates, and can optionally return your private slates as well. If the request body is omitted, the request will return only your public slates by default."
2021-03-24 07:10:26 +03:00
/>
<CodeBlock
2021-03-30 04:19:36 +03:00
children={code}
2021-03-24 07:10:26 +03:00
language={language}
2021-03-30 04:19:36 +03:00
style={{ maxWidth: "820px" }}
title="Get all slates"
multiLang="true"
onLanguageChange={this.props.onLanguageChange}
2021-03-24 07:10:26 +03:00
/>
</React.Fragment>
);
2021-03-22 21:17:42 +03:00
}
}