mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-25 04:20:02 +00:00
OpenAPI: Support Go Sample Request
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'fumadocs-openapi': minor
|
||||
---
|
||||
|
||||
Support Go Sample Request
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'fumadocs-openapi': minor
|
||||
---
|
||||
|
||||
Replace Response Table of Tabs
|
||||
@@ -57,9 +57,11 @@ export default function Page({
|
||||
<h1 className="text-3xl font-bold text-fd-foreground sm:text-4xl">
|
||||
{page.data.title}
|
||||
</h1>
|
||||
<p className="mb-8 text-lg text-fd-muted-foreground">
|
||||
{page.data.description}
|
||||
</p>
|
||||
{page.data.description ? (
|
||||
<p className="mb-8 text-lg text-fd-muted-foreground">
|
||||
{page.data.description}
|
||||
</p>
|
||||
) : null}
|
||||
<DocsBody>
|
||||
{preview && preview in Preview ? Preview[preview] : null}
|
||||
<page.data.exports.default
|
||||
|
||||
@@ -1,18 +1,13 @@
|
||||
import type { OpenAPIV3 as OpenAPI } from 'openapi-types';
|
||||
import { sample } from 'openapi-sampler';
|
||||
import type { MethodInformation } from '@/types';
|
||||
import {
|
||||
getPreferredMedia,
|
||||
toSampleInput,
|
||||
noRef,
|
||||
getPreferredType,
|
||||
} from '@/utils/schema';
|
||||
import { toSampleInput, noRef, getPreferredType } from '@/utils/schema';
|
||||
import { generateInput } from '@/utils/generate-input';
|
||||
|
||||
/**
|
||||
* Sample info of endpoint
|
||||
*/
|
||||
export interface Endpoint {
|
||||
export interface EndpointSample {
|
||||
/**
|
||||
* Request URL, including path and query parameters
|
||||
*/
|
||||
@@ -23,28 +18,30 @@ export interface Endpoint {
|
||||
mediaType: string;
|
||||
sample: unknown;
|
||||
};
|
||||
responses: Record<string, Response>;
|
||||
parameters: Parameter[];
|
||||
responses: Record<string, ResponseSample>;
|
||||
parameters: ParameterSample[];
|
||||
}
|
||||
|
||||
interface Response {
|
||||
interface ResponseSample {
|
||||
mediaType: string;
|
||||
sample: unknown;
|
||||
schema: OpenAPI.SchemaObject;
|
||||
}
|
||||
|
||||
interface Parameter {
|
||||
interface ParameterSample {
|
||||
name: string;
|
||||
in: string;
|
||||
schema: OpenAPI.SchemaObject;
|
||||
sample: unknown;
|
||||
}
|
||||
|
||||
export function createEndpoint(
|
||||
export function createSample(
|
||||
path: string,
|
||||
method: MethodInformation,
|
||||
baseUrl: string,
|
||||
): Endpoint {
|
||||
const params: Parameter[] = [];
|
||||
const responses: Endpoint['responses'] = {};
|
||||
): EndpointSample {
|
||||
const params: ParameterSample[] = [];
|
||||
const responses: EndpointSample['responses'] = {};
|
||||
|
||||
for (const param of method.parameters) {
|
||||
if (param.schema) {
|
||||
@@ -73,7 +70,7 @@ export function createEndpoint(
|
||||
}
|
||||
}
|
||||
|
||||
let bodyOutput: Endpoint['body'];
|
||||
let bodyOutput: EndpointSample['body'];
|
||||
|
||||
if (method.requestBody) {
|
||||
const body = noRef(method.requestBody).content;
|
||||
@@ -90,12 +87,20 @@ export function createEndpoint(
|
||||
}
|
||||
|
||||
for (const [code, value] of Object.entries(method.responses)) {
|
||||
const mediaTypes = noRef(value).content ?? {};
|
||||
const responseSchema = noRef(getPreferredMedia(mediaTypes)?.schema);
|
||||
const content = noRef(value).content;
|
||||
if (!content) continue;
|
||||
|
||||
const mediaType = getPreferredType(content) as string;
|
||||
if (!mediaType) continue;
|
||||
|
||||
const responseSchema = noRef(content[mediaType].schema);
|
||||
if (!responseSchema) continue;
|
||||
|
||||
responses[code] = {
|
||||
mediaType,
|
||||
sample:
|
||||
content[mediaType].example ??
|
||||
generateInput(method.method, responseSchema),
|
||||
schema: responseSchema,
|
||||
};
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import type { OpenAPIV3 as OpenAPI } from 'openapi-types';
|
||||
import { createEndpoint, type Endpoint } from '@/endpoint';
|
||||
import { getExampleResponse } from '@/utils/generate-response';
|
||||
import { createSample, type EndpointSample } from '@/create-sample';
|
||||
import * as CURL from '@/requests/curl';
|
||||
import * as JS from '@/requests/javascript';
|
||||
import * as Go from '@/requests/go';
|
||||
import { type MethodInformation, type RenderContext } from '@/types';
|
||||
import { noRef, getPreferredMedia, getPreferredType } from '@/utils/schema';
|
||||
import { getTypescriptSchema } from '@/utils/get-typescript-schema';
|
||||
@@ -74,7 +74,7 @@ export async function renderOperation(
|
||||
}
|
||||
|
||||
const parameterGroups = new Map<string, string[]>();
|
||||
const endpoint = createEndpoint(path, method, ctx.baseUrl);
|
||||
const endpoint = createSample(path, method, ctx.baseUrl);
|
||||
|
||||
for (const param of method.parameters) {
|
||||
const schema = noRef(
|
||||
@@ -117,8 +117,6 @@ export async function renderOperation(
|
||||
info.push(heading(level, group), ...parameters);
|
||||
}
|
||||
|
||||
info.push(getResponseTable(method));
|
||||
|
||||
const samples: CodeSample[] = dedupe([
|
||||
{
|
||||
label: 'cURL',
|
||||
@@ -130,6 +128,11 @@ export async function renderOperation(
|
||||
source: JS.getSampleRequest(endpoint),
|
||||
lang: 'js',
|
||||
},
|
||||
{
|
||||
label: 'Go',
|
||||
source: Go.getSampleRequest(endpoint),
|
||||
lang: 'go',
|
||||
},
|
||||
...(ctx.generateCodeSamples ? await ctx.generateCodeSamples(endpoint) : []),
|
||||
...((method as CustomProperty)['x-codeSamples'] ?? []),
|
||||
]);
|
||||
@@ -245,20 +248,8 @@ function getAuthSection(
|
||||
return info.join('\n\n');
|
||||
}
|
||||
|
||||
function getResponseTable(operation: OpenAPI.OperationObject): string {
|
||||
const table: string[] = [];
|
||||
table.push(`| Status code | Description |`);
|
||||
table.push(`| ----------- | ----------- |`);
|
||||
|
||||
Object.entries(operation.responses).forEach(([code, value]) => {
|
||||
table.push(`| \`${code}\` | ${noRef(value).description} |`);
|
||||
});
|
||||
|
||||
return table.join('\n');
|
||||
}
|
||||
|
||||
async function getResponseTabs(
|
||||
endpoint: Endpoint,
|
||||
endpoint: EndpointSample,
|
||||
operation: OpenAPI.OperationObject,
|
||||
{ renderer, generateTypeScriptSchema }: RenderContext,
|
||||
): Promise<string> {
|
||||
@@ -266,33 +257,37 @@ async function getResponseTabs(
|
||||
const child: string[] = [];
|
||||
|
||||
for (const code of Object.keys(operation.responses)) {
|
||||
const example = getExampleResponse(endpoint, code);
|
||||
let ts: string | undefined;
|
||||
const tabs: string[] = [];
|
||||
|
||||
if (code in endpoint.responses) {
|
||||
tabs.push(
|
||||
renderer.ExampleResponse(
|
||||
JSON.stringify(endpoint.responses[code].sample, null, 2),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
let ts: string | undefined;
|
||||
if (generateTypeScriptSchema) {
|
||||
ts = await generateTypeScriptSchema(endpoint, code);
|
||||
} else if (generateTypeScriptSchema === undefined) {
|
||||
ts = await getTypescriptSchema(endpoint, code);
|
||||
}
|
||||
|
||||
const description =
|
||||
code in endpoint.responses
|
||||
? endpoint.responses[code].schema.description
|
||||
: undefined;
|
||||
if (ts) tabs.push(renderer.TypeScriptResponse(ts));
|
||||
|
||||
if (example) {
|
||||
items.push(code);
|
||||
let description = noRef(operation.responses[code]).description;
|
||||
|
||||
child.push(
|
||||
renderer.Response({ value: code }, [
|
||||
p(description),
|
||||
renderer.ResponseTypes([
|
||||
renderer.ExampleResponse(example),
|
||||
...(ts ? [renderer.TypeScriptResponse(ts)] : []),
|
||||
]),
|
||||
]),
|
||||
);
|
||||
}
|
||||
if (!description && code in endpoint.responses)
|
||||
description = endpoint.responses[code].schema.description ?? '';
|
||||
|
||||
items.push(code);
|
||||
child.push(
|
||||
renderer.Response({ value: code }, [
|
||||
p(description),
|
||||
...(tabs.length > 0 ? [renderer.ResponseTypes(tabs)] : []),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
if (items.length === 0) return '';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { type Endpoint } from '@/endpoint';
|
||||
import { type EndpointSample } from '@/create-sample';
|
||||
import { toSampleInput } from '@/utils/schema';
|
||||
|
||||
export function getSampleRequest(endpoint: Endpoint): string {
|
||||
export function getSampleRequest(endpoint: EndpointSample): string {
|
||||
const s: string[] = [];
|
||||
|
||||
s.push(`curl -X ${endpoint.method} "${endpoint.url}"`);
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
import { type EndpointSample } from '@/create-sample';
|
||||
import { toSampleInput } from '@/utils/schema';
|
||||
|
||||
export function getSampleRequest(endpoint: EndpointSample): string {
|
||||
const imports = ['fmt', 'net/http', 'io/ioutil'];
|
||||
const headers = new Map<string, string>();
|
||||
const cookies = new Map<string, string>();
|
||||
const variables = new Map<string, string>();
|
||||
|
||||
// additional lines before initializing request
|
||||
const additional: string[] = [];
|
||||
|
||||
for (const p of endpoint.parameters) {
|
||||
if (p.in === 'header') headers.set(p.name, JSON.stringify(p.sample));
|
||||
if (p.in === 'cookie') cookies.set(p.name, toSampleInput(p.sample));
|
||||
}
|
||||
|
||||
variables.set('url', JSON.stringify(endpoint.url));
|
||||
|
||||
if (cookies.size > 0)
|
||||
headers.set(
|
||||
'Cookie',
|
||||
JSON.stringify(
|
||||
Array.from(cookies.entries())
|
||||
.map(([key, value]) => `${key}=${value}`)
|
||||
.join('; '),
|
||||
),
|
||||
);
|
||||
|
||||
if (endpoint.body) {
|
||||
headers.set('Content-Type', `"${endpoint.body.mediaType}"`);
|
||||
|
||||
if (endpoint.body.mediaType === 'application/json') {
|
||||
imports.push('strings');
|
||||
variables.set(
|
||||
'payload',
|
||||
`strings.NewReader(\`${JSON.stringify(
|
||||
endpoint.body.sample,
|
||||
null,
|
||||
2,
|
||||
).replaceAll('\n', '\n ')}\`)`,
|
||||
);
|
||||
}
|
||||
if (
|
||||
endpoint.body.mediaType === 'multipart/form-data' &&
|
||||
typeof endpoint.body.sample === 'object'
|
||||
) {
|
||||
imports.push('mime/multipart', 'bytes');
|
||||
|
||||
variables.set('payload', `new(bytes.Buffer)`);
|
||||
variables.set('mp', 'multipart.NewWriter(payload)');
|
||||
|
||||
for (const [key, value] of Object.entries(endpoint.body.sample ?? {})) {
|
||||
additional.push(
|
||||
`mp.WriteField("${key}", ${JSON.stringify(toSampleInput(value))})`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return `package main
|
||||
|
||||
import (
|
||||
${imports.map((v) => ` "${v}"`).join('\n')}
|
||||
)
|
||||
|
||||
func main() {
|
||||
${Array.from(variables.entries())
|
||||
.map(([k, v]) => ` ${k} := ${v}`)
|
||||
.join('\n')}
|
||||
${additional.join('\n ')}
|
||||
req, _ := http.NewRequest("${endpoint.method}", url, ${variables.has('payload') ? 'payload' : 'nil'})
|
||||
${Array.from(headers.entries())
|
||||
.map(([key, value]) => `req.Header.Add("${key}", ${value})`)
|
||||
.join('\n')}
|
||||
res, _ := http.DefaultClient.Do(req)
|
||||
defer res.Body.Close()
|
||||
body, _ := ioutil.ReadAll(res.Body)
|
||||
|
||||
fmt.Println(res)
|
||||
fmt.Println(string(body))
|
||||
}`;
|
||||
}
|
||||
@@ -1,21 +1,40 @@
|
||||
import { type Endpoint } from '@/endpoint';
|
||||
import { generateInput } from '@/utils/generate-input';
|
||||
import { type EndpointSample } from '@/create-sample';
|
||||
import { toSampleInput } from '@/utils/schema';
|
||||
|
||||
export function getSampleRequest(endpoint: Endpoint): string {
|
||||
export function getSampleRequest(endpoint: EndpointSample): string {
|
||||
const s: string[] = [];
|
||||
const options = new Map<string, string>();
|
||||
const headers: Record<string, unknown> = {};
|
||||
const headers = new Map<string, unknown>();
|
||||
const cookies = new Map<string, unknown>();
|
||||
|
||||
for (const param of endpoint.parameters) {
|
||||
if (param.in === 'header') {
|
||||
headers[param.name] = generateInput(endpoint.method, param.schema);
|
||||
headers.set(param.name, param.sample);
|
||||
}
|
||||
|
||||
if (param.in === 'cookie') {
|
||||
cookies.set(param.name, param.sample);
|
||||
}
|
||||
}
|
||||
|
||||
options.set('method', JSON.stringify(endpoint.method));
|
||||
if (cookies.size > 0) {
|
||||
headers.set(
|
||||
'cookie',
|
||||
Array.from(cookies.entries())
|
||||
.map(([key, value]) => `${key}=${toSampleInput(value)}`)
|
||||
.join('; '),
|
||||
);
|
||||
}
|
||||
|
||||
if (Object.keys(headers).length > 0) {
|
||||
options.set('headers', JSON.stringify(headers, undefined, 2));
|
||||
if (headers.size > 0) {
|
||||
options.set(
|
||||
'headers',
|
||||
JSON.stringify(
|
||||
Object.fromEntries(headers.entries()),
|
||||
undefined,
|
||||
2,
|
||||
).replaceAll('\n', '\n '),
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
@@ -32,10 +51,11 @@ export function getSampleRequest(endpoint: Endpoint): string {
|
||||
} else if (endpoint.body) {
|
||||
options.set(
|
||||
'body',
|
||||
`JSON.stringify(${JSON.stringify(endpoint.body.sample, null, 2)
|
||||
.split('\n')
|
||||
.map((v, i) => (i > 0 ? ` ${v}` : v))
|
||||
.join('\n')})`,
|
||||
`JSON.stringify(${JSON.stringify(
|
||||
endpoint.body.sample,
|
||||
null,
|
||||
2,
|
||||
).replaceAll('\n', '\n ')})`,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { OpenAPIV3 as OpenAPI } from 'openapi-types';
|
||||
import { type Renderer } from '@/render/renderer';
|
||||
import type { Endpoint } from '@/endpoint';
|
||||
import type { EndpointSample } from '@/create-sample';
|
||||
import type { CodeSample } from '@/render/operation';
|
||||
|
||||
export interface RouteInformation {
|
||||
@@ -31,11 +31,11 @@ export interface RenderContext {
|
||||
* @param code - status code
|
||||
*/
|
||||
generateTypeScriptSchema?:
|
||||
| ((endpoint: Endpoint, code: string) => Awaitable<string>)
|
||||
| ((endpoint: EndpointSample, code: string) => Awaitable<string>)
|
||||
| false;
|
||||
|
||||
/**
|
||||
* Generate code samples for endpoint.
|
||||
*/
|
||||
generateCodeSamples?: (endpoint: Endpoint) => Awaitable<CodeSample[]>;
|
||||
generateCodeSamples?: (endpoint: EndpointSample) => Awaitable<CodeSample[]>;
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
import { type Endpoint } from '@/endpoint';
|
||||
import { generateInput } from '@/utils/generate-input';
|
||||
|
||||
export function getExampleResponse(
|
||||
endpoint: Endpoint,
|
||||
code: string,
|
||||
): string | undefined {
|
||||
if (code in endpoint.responses) {
|
||||
const value = generateInput(
|
||||
endpoint.method,
|
||||
endpoint.responses[code].schema,
|
||||
);
|
||||
|
||||
return JSON.stringify(value, null, 2);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import { compile } from 'json-schema-to-typescript';
|
||||
import type { Endpoint } from '@/endpoint';
|
||||
import type { EndpointSample } from '@/create-sample';
|
||||
|
||||
export async function getTypescriptSchema(
|
||||
endpoint: Endpoint,
|
||||
endpoint: EndpointSample,
|
||||
code: string,
|
||||
): Promise<string | undefined> {
|
||||
if (code in endpoint.responses) {
|
||||
|
||||
@@ -72,17 +72,11 @@ The number of days per page.
|
||||
|
||||
</Property>
|
||||
|
||||
| Status code | Description |
|
||||
| ----------- | ----------- |
|
||||
| `200` | Success |
|
||||
| `400` | Bad request |
|
||||
| `404` | Not found |
|
||||
|
||||
</APIInfo>
|
||||
|
||||
<APIExample>
|
||||
|
||||
<Requests items={["cURL","JavaScript"]}>
|
||||
<Requests items={["cURL","JavaScript","Go"]}>
|
||||
|
||||
<Request value={"cURL"}>
|
||||
|
||||
@@ -96,19 +90,46 @@ curl -X GET "https://api.fake-museum-example.com/v1/special-events?startDate=202
|
||||
|
||||
```js
|
||||
fetch("https://api.fake-museum-example.com/v1/special-events?startDate=2023-02-23&endDate=2023-04-18&page=2&limit=15", {
|
||||
method: "GET"
|
||||
|
||||
});
|
||||
```
|
||||
|
||||
</Request>
|
||||
|
||||
<Request value={"Go"}>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
func main() {
|
||||
url := "https://api.fake-museum-example.com/v1/special-events?startDate=2023-02-23&endDate=2023-04-18&page=2&limit=15"
|
||||
|
||||
req, _ := http.NewRequest("GET", url, nil)
|
||||
|
||||
res, _ := http.DefaultClient.Do(req)
|
||||
defer res.Body.Close()
|
||||
body, _ := ioutil.ReadAll(res.Body)
|
||||
|
||||
fmt.Println(res)
|
||||
fmt.Println(string(body))
|
||||
}
|
||||
```
|
||||
|
||||
</Request>
|
||||
|
||||
</Requests>
|
||||
|
||||
<Responses items={["200"]}>
|
||||
<Responses items={["200","400","404"]}>
|
||||
|
||||
<Response value={"200"}>
|
||||
|
||||
A list of upcoming special events
|
||||
Success
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
@@ -171,6 +192,18 @@ export type Response = {
|
||||
|
||||
</Response>
|
||||
|
||||
<Response value={"400"}>
|
||||
|
||||
Bad request
|
||||
|
||||
</Response>
|
||||
|
||||
<Response value={"404"}>
|
||||
|
||||
Not found
|
||||
|
||||
</Response>
|
||||
|
||||
</Responses>
|
||||
|
||||
</APIExample>
|
||||
@@ -239,17 +272,11 @@ Price of a ticket for the special event
|
||||
|
||||
</Property>
|
||||
|
||||
| Status code | Description |
|
||||
| ----------- | ----------- |
|
||||
| `200` | Success |
|
||||
| `400` | Bad request |
|
||||
| `404` | Not found |
|
||||
|
||||
</APIInfo>
|
||||
|
||||
<APIExample>
|
||||
|
||||
<Requests items={["cURL","JavaScript"]}>
|
||||
<Requests items={["cURL","JavaScript","Go"]}>
|
||||
|
||||
<Request value={"cURL"}>
|
||||
|
||||
@@ -273,7 +300,6 @@ curl -X POST "https://api.fake-museum-example.com/v1/special-events" \
|
||||
|
||||
```js
|
||||
fetch("https://api.fake-museum-example.com/v1/special-events", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
"name": "Pirate Coding Workshop",
|
||||
"location": "Computer Room",
|
||||
@@ -288,13 +314,50 @@ fetch("https://api.fake-museum-example.com/v1/special-events", {
|
||||
|
||||
</Request>
|
||||
|
||||
<Request value={"Go"}>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
url := "https://api.fake-museum-example.com/v1/special-events"
|
||||
payload := strings.NewReader(`{
|
||||
"name": "Pirate Coding Workshop",
|
||||
"location": "Computer Room",
|
||||
"eventDescription": "Captain Blackbeard shares his love of the C...language. And possibly Arrrrr (R lang).",
|
||||
"dates": [
|
||||
"2023-10-29"
|
||||
],
|
||||
"price": 25
|
||||
}`)
|
||||
|
||||
req, _ := http.NewRequest("POST", url, payload)
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
res, _ := http.DefaultClient.Do(req)
|
||||
defer res.Body.Close()
|
||||
body, _ := ioutil.ReadAll(res.Body)
|
||||
|
||||
fmt.Println(res)
|
||||
fmt.Println(string(body))
|
||||
}
|
||||
```
|
||||
|
||||
</Request>
|
||||
|
||||
</Requests>
|
||||
|
||||
<Responses items={["200"]}>
|
||||
<Responses items={["200","400","404"]}>
|
||||
|
||||
<Response value={"200"}>
|
||||
|
||||
Information about a special event.
|
||||
Success
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
@@ -355,6 +418,18 @@ export interface Response {
|
||||
|
||||
</Response>
|
||||
|
||||
<Response value={"400"}>
|
||||
|
||||
Bad request
|
||||
|
||||
</Response>
|
||||
|
||||
<Response value={"404"}>
|
||||
|
||||
Not found
|
||||
|
||||
</Response>
|
||||
|
||||
</Responses>
|
||||
|
||||
</APIExample>
|
||||
@@ -393,17 +468,11 @@ An identifier for a special event.
|
||||
|
||||
</Property>
|
||||
|
||||
| Status code | Description |
|
||||
| ----------- | ----------- |
|
||||
| `200` | Success |
|
||||
| `400` | Bad request |
|
||||
| `404` | Not found |
|
||||
|
||||
</APIInfo>
|
||||
|
||||
<APIExample>
|
||||
|
||||
<Requests items={["cURL","JavaScript"]}>
|
||||
<Requests items={["cURL","JavaScript","Go"]}>
|
||||
|
||||
<Request value={"cURL"}>
|
||||
|
||||
@@ -417,19 +486,46 @@ curl -X GET "https://api.fake-museum-example.com/v1/special-events/dad4bce8-f5cb
|
||||
|
||||
```js
|
||||
fetch("https://api.fake-museum-example.com/v1/special-events/dad4bce8-f5cb-4078-a211-995864315e39", {
|
||||
method: "GET"
|
||||
|
||||
});
|
||||
```
|
||||
|
||||
</Request>
|
||||
|
||||
<Request value={"Go"}>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
func main() {
|
||||
url := "https://api.fake-museum-example.com/v1/special-events/dad4bce8-f5cb-4078-a211-995864315e39"
|
||||
|
||||
req, _ := http.NewRequest("GET", url, nil)
|
||||
|
||||
res, _ := http.DefaultClient.Do(req)
|
||||
defer res.Body.Close()
|
||||
body, _ := ioutil.ReadAll(res.Body)
|
||||
|
||||
fmt.Println(res)
|
||||
fmt.Println(string(body))
|
||||
}
|
||||
```
|
||||
|
||||
</Request>
|
||||
|
||||
</Requests>
|
||||
|
||||
<Responses items={["200"]}>
|
||||
<Responses items={["200","400","404"]}>
|
||||
|
||||
<Response value={"200"}>
|
||||
|
||||
Information about a special event.
|
||||
Success
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
@@ -490,6 +586,18 @@ export interface Response {
|
||||
|
||||
</Response>
|
||||
|
||||
<Response value={"400"}>
|
||||
|
||||
Bad request
|
||||
|
||||
</Response>
|
||||
|
||||
<Response value={"404"}>
|
||||
|
||||
Not found
|
||||
|
||||
</Response>
|
||||
|
||||
</Responses>
|
||||
|
||||
</APIExample>
|
||||
@@ -570,17 +678,11 @@ An identifier for a special event.
|
||||
|
||||
</Property>
|
||||
|
||||
| Status code | Description |
|
||||
| ----------- | ----------- |
|
||||
| `200` | Success |
|
||||
| `400` | Bad request |
|
||||
| `404` | Not found |
|
||||
|
||||
</APIInfo>
|
||||
|
||||
<APIExample>
|
||||
|
||||
<Requests items={["cURL","JavaScript"]}>
|
||||
<Requests items={["cURL","JavaScript","Go"]}>
|
||||
|
||||
<Request value={"cURL"}>
|
||||
|
||||
@@ -604,7 +706,6 @@ curl -X PATCH "https://api.fake-museum-example.com/v1/special-events/dad4bce8-f5
|
||||
|
||||
```js
|
||||
fetch("https://api.fake-museum-example.com/v1/special-events/dad4bce8-f5cb-4078-a211-995864315e39", {
|
||||
method: "PATCH",
|
||||
body: JSON.stringify({
|
||||
"name": "Pirate Coding Workshop",
|
||||
"location": "Computer Room",
|
||||
@@ -619,13 +720,50 @@ fetch("https://api.fake-museum-example.com/v1/special-events/dad4bce8-f5cb-4078-
|
||||
|
||||
</Request>
|
||||
|
||||
<Request value={"Go"}>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
url := "https://api.fake-museum-example.com/v1/special-events/dad4bce8-f5cb-4078-a211-995864315e39"
|
||||
payload := strings.NewReader(`{
|
||||
"name": "Pirate Coding Workshop",
|
||||
"location": "Computer Room",
|
||||
"eventDescription": "Captain Blackbeard shares his love of the C...language. And possibly Arrrrr (R lang).",
|
||||
"dates": [
|
||||
"2023-10-29"
|
||||
],
|
||||
"price": 25
|
||||
}`)
|
||||
|
||||
req, _ := http.NewRequest("PATCH", url, payload)
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
res, _ := http.DefaultClient.Do(req)
|
||||
defer res.Body.Close()
|
||||
body, _ := ioutil.ReadAll(res.Body)
|
||||
|
||||
fmt.Println(res)
|
||||
fmt.Println(string(body))
|
||||
}
|
||||
```
|
||||
|
||||
</Request>
|
||||
|
||||
</Requests>
|
||||
|
||||
<Responses items={["200"]}>
|
||||
<Responses items={["200","400","404"]}>
|
||||
|
||||
<Response value={"200"}>
|
||||
|
||||
Information about a special event.
|
||||
Success
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
@@ -686,6 +824,18 @@ export interface Response {
|
||||
|
||||
</Response>
|
||||
|
||||
<Response value={"400"}>
|
||||
|
||||
Bad request
|
||||
|
||||
</Response>
|
||||
|
||||
<Response value={"404"}>
|
||||
|
||||
Not found
|
||||
|
||||
</Response>
|
||||
|
||||
</Responses>
|
||||
|
||||
</APIExample>
|
||||
@@ -724,18 +874,11 @@ An identifier for a special event.
|
||||
|
||||
</Property>
|
||||
|
||||
| Status code | Description |
|
||||
| ----------- | ----------- |
|
||||
| `204` | Success - no content |
|
||||
| `400` | Bad request |
|
||||
| `401` | Unauthorized |
|
||||
| `404` | Not found |
|
||||
|
||||
</APIInfo>
|
||||
|
||||
<APIExample>
|
||||
|
||||
<Requests items={["cURL","JavaScript"]}>
|
||||
<Requests items={["cURL","JavaScript","Go"]}>
|
||||
|
||||
<Request value={"cURL"}>
|
||||
|
||||
@@ -749,14 +892,69 @@ curl -X DELETE "https://api.fake-museum-example.com/v1/special-events/dad4bce8-f
|
||||
|
||||
```js
|
||||
fetch("https://api.fake-museum-example.com/v1/special-events/dad4bce8-f5cb-4078-a211-995864315e39", {
|
||||
method: "DELETE"
|
||||
|
||||
});
|
||||
```
|
||||
|
||||
</Request>
|
||||
|
||||
<Request value={"Go"}>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
func main() {
|
||||
url := "https://api.fake-museum-example.com/v1/special-events/dad4bce8-f5cb-4078-a211-995864315e39"
|
||||
|
||||
req, _ := http.NewRequest("DELETE", url, nil)
|
||||
|
||||
res, _ := http.DefaultClient.Do(req)
|
||||
defer res.Body.Close()
|
||||
body, _ := ioutil.ReadAll(res.Body)
|
||||
|
||||
fmt.Println(res)
|
||||
fmt.Println(string(body))
|
||||
}
|
||||
```
|
||||
|
||||
</Request>
|
||||
|
||||
</Requests>
|
||||
|
||||
<Responses items={["204","400","401","404"]}>
|
||||
|
||||
<Response value={"204"}>
|
||||
|
||||
Success - no content
|
||||
|
||||
</Response>
|
||||
|
||||
<Response value={"400"}>
|
||||
|
||||
Bad request
|
||||
|
||||
</Response>
|
||||
|
||||
<Response value={"401"}>
|
||||
|
||||
Unauthorized
|
||||
|
||||
</Response>
|
||||
|
||||
<Response value={"404"}>
|
||||
|
||||
Not found
|
||||
|
||||
</Response>
|
||||
|
||||
</Responses>
|
||||
|
||||
</APIExample>
|
||||
|
||||
</API>
|
||||
|
||||
@@ -62,17 +62,11 @@ The number of days per page.
|
||||
|
||||
</Property>
|
||||
|
||||
| Status code | Description |
|
||||
| ----------- | ----------- |
|
||||
| `200` | Success |
|
||||
| `400` | Bad request |
|
||||
| `404` | Not found |
|
||||
|
||||
</APIInfo>
|
||||
|
||||
<APIExample>
|
||||
|
||||
<Requests items={["cURL","JavaScript","List all unwatered plants"]}>
|
||||
<Requests items={["cURL","JavaScript","Go","List all unwatered plants"]}>
|
||||
|
||||
<Request value={"cURL"}>
|
||||
|
||||
@@ -86,12 +80,39 @@ curl -X GET "https://api.fake-museum-example.com/v1/museum-hours?startDate=2023-
|
||||
|
||||
```js
|
||||
fetch("https://api.fake-museum-example.com/v1/museum-hours?startDate=2023-02-23&page=2&limit=15", {
|
||||
method: "GET"
|
||||
|
||||
});
|
||||
```
|
||||
|
||||
</Request>
|
||||
|
||||
<Request value={"Go"}>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
func main() {
|
||||
url := "https://api.fake-museum-example.com/v1/museum-hours?startDate=2023-02-23&page=2&limit=15"
|
||||
|
||||
req, _ := http.NewRequest("GET", url, nil)
|
||||
|
||||
res, _ := http.DefaultClient.Do(req)
|
||||
defer res.Body.Close()
|
||||
body, _ := ioutil.ReadAll(res.Body)
|
||||
|
||||
fmt.Println(res)
|
||||
fmt.Println(string(body))
|
||||
}
|
||||
```
|
||||
|
||||
</Request>
|
||||
|
||||
<Request value={"List all unwatered plants"}>
|
||||
|
||||
```bash
|
||||
@@ -102,11 +123,11 @@ planter list -u
|
||||
|
||||
</Requests>
|
||||
|
||||
<Responses items={["200"]}>
|
||||
<Responses items={["200","400","404"]}>
|
||||
|
||||
<Response value={"200"}>
|
||||
|
||||
List of museum operating hours for consecutive days.
|
||||
Success
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
@@ -152,6 +173,18 @@ export type Response = {
|
||||
|
||||
</Response>
|
||||
|
||||
<Response value={"400"}>
|
||||
|
||||
Bad request
|
||||
|
||||
</Response>
|
||||
|
||||
<Response value={"404"}>
|
||||
|
||||
Not found
|
||||
|
||||
</Response>
|
||||
|
||||
</Responses>
|
||||
|
||||
</APIExample>
|
||||
|
||||
@@ -78,17 +78,11 @@ Phone number for the ticket purchaser (optional).
|
||||
|
||||
</Property>
|
||||
|
||||
| Status code | Description |
|
||||
| ----------- | ----------- |
|
||||
| `200` | Success |
|
||||
| `400` | Bad request |
|
||||
| `404` | Not found |
|
||||
|
||||
</APIInfo>
|
||||
|
||||
<APIExample>
|
||||
|
||||
<Requests items={["cURL","JavaScript"]}>
|
||||
<Requests items={["cURL","JavaScript","Go"]}>
|
||||
|
||||
<Request value={"cURL"}>
|
||||
|
||||
@@ -110,7 +104,6 @@ curl -X POST "https://api.fake-museum-example.com/v1/tickets" \
|
||||
|
||||
```js
|
||||
fetch("https://api.fake-museum-example.com/v1/tickets", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
"ticketType": "event",
|
||||
"eventId": "3be6453c-03eb-4357-ae5a-984a0e574a54",
|
||||
@@ -123,13 +116,48 @@ fetch("https://api.fake-museum-example.com/v1/tickets", {
|
||||
|
||||
</Request>
|
||||
|
||||
<Request value={"Go"}>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
url := "https://api.fake-museum-example.com/v1/tickets"
|
||||
payload := strings.NewReader(`{
|
||||
"ticketType": "event",
|
||||
"eventId": "3be6453c-03eb-4357-ae5a-984a0e574a54",
|
||||
"ticketDate": "2023-10-29",
|
||||
"email": "[email protected]",
|
||||
"phone": "+1(234)-567-8910"
|
||||
}`)
|
||||
|
||||
req, _ := http.NewRequest("POST", url, payload)
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
res, _ := http.DefaultClient.Do(req)
|
||||
defer res.Body.Close()
|
||||
body, _ := ioutil.ReadAll(res.Body)
|
||||
|
||||
fmt.Println(res)
|
||||
fmt.Println(string(body))
|
||||
}
|
||||
```
|
||||
|
||||
</Request>
|
||||
|
||||
</Requests>
|
||||
|
||||
<Responses items={["200"]}>
|
||||
<Responses items={["200","400","404"]}>
|
||||
|
||||
<Response value={"200"}>
|
||||
|
||||
Details for a museum ticket after a successful purchase.
|
||||
Success
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
@@ -188,6 +216,18 @@ export interface Response {
|
||||
|
||||
</Response>
|
||||
|
||||
<Response value={"400"}>
|
||||
|
||||
Bad request
|
||||
|
||||
</Response>
|
||||
|
||||
<Response value={"404"}>
|
||||
|
||||
Not found
|
||||
|
||||
</Response>
|
||||
|
||||
</Responses>
|
||||
|
||||
</APIExample>
|
||||
@@ -226,17 +266,11 @@ An identifier for a ticket to a museum event. Used to generate ticket image.
|
||||
|
||||
</Property>
|
||||
|
||||
| Status code | Description |
|
||||
| ----------- | ----------- |
|
||||
| `200` | Scannable event ticket in image format |
|
||||
| `400` | Bad request |
|
||||
| `404` | Not found |
|
||||
|
||||
</APIInfo>
|
||||
|
||||
<APIExample>
|
||||
|
||||
<Requests items={["cURL","JavaScript"]}>
|
||||
<Requests items={["cURL","JavaScript","Go"]}>
|
||||
|
||||
<Request value={"cURL"}>
|
||||
|
||||
@@ -250,19 +284,46 @@ curl -X GET "https://api.fake-museum-example.com/v1/tickets/a54a57ca-36f8-421b-a
|
||||
|
||||
```js
|
||||
fetch("https://api.fake-museum-example.com/v1/tickets/a54a57ca-36f8-421b-a6b4-2e8f26858a4c/qr", {
|
||||
method: "GET"
|
||||
|
||||
});
|
||||
```
|
||||
|
||||
</Request>
|
||||
|
||||
<Request value={"Go"}>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
func main() {
|
||||
url := "https://api.fake-museum-example.com/v1/tickets/a54a57ca-36f8-421b-a6b4-2e8f26858a4c/qr"
|
||||
|
||||
req, _ := http.NewRequest("GET", url, nil)
|
||||
|
||||
res, _ := http.DefaultClient.Do(req)
|
||||
defer res.Body.Close()
|
||||
body, _ := ioutil.ReadAll(res.Body)
|
||||
|
||||
fmt.Println(res)
|
||||
fmt.Println(string(body))
|
||||
}
|
||||
```
|
||||
|
||||
</Request>
|
||||
|
||||
</Requests>
|
||||
|
||||
<Responses items={["200"]}>
|
||||
<Responses items={["200","400","404"]}>
|
||||
|
||||
<Response value={"200"}>
|
||||
|
||||
An image of a ticket with a QR code used for museum or event entry.
|
||||
Scannable event ticket in image format
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
@@ -289,6 +350,18 @@ export type Response = string;
|
||||
|
||||
</Response>
|
||||
|
||||
<Response value={"400"}>
|
||||
|
||||
Bad request
|
||||
|
||||
</Response>
|
||||
|
||||
<Response value={"404"}>
|
||||
|
||||
Not found
|
||||
|
||||
</Response>
|
||||
|
||||
</Responses>
|
||||
|
||||
</APIExample>
|
||||
|
||||
@@ -29,16 +29,11 @@ How many items to return at one time (max 100)
|
||||
|
||||
</Property>
|
||||
|
||||
| Status code | Description |
|
||||
| ----------- | ----------- |
|
||||
| `200` | A paged array of pets |
|
||||
| `default` | unexpected error |
|
||||
|
||||
</APIInfo>
|
||||
|
||||
<APIExample>
|
||||
|
||||
<Requests items={["cURL","JavaScript"]}>
|
||||
<Requests items={["cURL","JavaScript","Go"]}>
|
||||
|
||||
<Request value={"cURL"}>
|
||||
|
||||
@@ -52,18 +47,47 @@ curl -X GET "http://petstore.swagger.io/v1/pets?limit=100"
|
||||
|
||||
```js
|
||||
fetch("http://petstore.swagger.io/v1/pets?limit=100", {
|
||||
method: "GET"
|
||||
|
||||
});
|
||||
```
|
||||
|
||||
</Request>
|
||||
|
||||
<Request value={"Go"}>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
func main() {
|
||||
url := "http://petstore.swagger.io/v1/pets?limit=100"
|
||||
|
||||
req, _ := http.NewRequest("GET", url, nil)
|
||||
|
||||
res, _ := http.DefaultClient.Do(req)
|
||||
defer res.Body.Close()
|
||||
body, _ := ioutil.ReadAll(res.Body)
|
||||
|
||||
fmt.Println(res)
|
||||
fmt.Println(string(body))
|
||||
}
|
||||
```
|
||||
|
||||
</Request>
|
||||
|
||||
</Requests>
|
||||
|
||||
<Responses items={["200","default"]}>
|
||||
|
||||
<Response value={"200"}>
|
||||
|
||||
A paged array of pets
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -101,6 +125,8 @@ export type Response = {
|
||||
|
||||
<Response value={"default"}>
|
||||
|
||||
unexpected error
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -161,16 +187,11 @@ export interface Response {
|
||||
|
||||
</Property>
|
||||
|
||||
| Status code | Description |
|
||||
| ----------- | ----------- |
|
||||
| `201` | Null response |
|
||||
| `default` | unexpected error |
|
||||
|
||||
</APIInfo>
|
||||
|
||||
<APIExample>
|
||||
|
||||
<Requests items={["cURL","JavaScript"]}>
|
||||
<Requests items={["cURL","JavaScript","Go"]}>
|
||||
|
||||
<Request value={"cURL"}>
|
||||
|
||||
@@ -190,7 +211,6 @@ curl -X POST "http://petstore.swagger.io/v1/pets" \
|
||||
|
||||
```js
|
||||
fetch("http://petstore.swagger.io/v1/pets", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
"id": 0,
|
||||
"name": "string",
|
||||
@@ -201,12 +221,53 @@ fetch("http://petstore.swagger.io/v1/pets", {
|
||||
|
||||
</Request>
|
||||
|
||||
<Request value={"Go"}>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
url := "http://petstore.swagger.io/v1/pets"
|
||||
payload := strings.NewReader(`{
|
||||
"id": 0,
|
||||
"name": "string",
|
||||
"tag": "string"
|
||||
}`)
|
||||
|
||||
req, _ := http.NewRequest("POST", url, payload)
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
res, _ := http.DefaultClient.Do(req)
|
||||
defer res.Body.Close()
|
||||
body, _ := ioutil.ReadAll(res.Body)
|
||||
|
||||
fmt.Println(res)
|
||||
fmt.Println(string(body))
|
||||
}
|
||||
```
|
||||
|
||||
</Request>
|
||||
|
||||
</Requests>
|
||||
|
||||
<Responses items={["default"]}>
|
||||
<Responses items={["201","default"]}>
|
||||
|
||||
<Response value={"201"}>
|
||||
|
||||
Null response
|
||||
|
||||
</Response>
|
||||
|
||||
<Response value={"default"}>
|
||||
|
||||
unexpected error
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -259,16 +320,11 @@ The id of the pet to retrieve
|
||||
|
||||
</Property>
|
||||
|
||||
| Status code | Description |
|
||||
| ----------- | ----------- |
|
||||
| `200` | Expected response to a valid request |
|
||||
| `default` | unexpected error |
|
||||
|
||||
</APIInfo>
|
||||
|
||||
<APIExample>
|
||||
|
||||
<Requests items={["cURL","JavaScript"]}>
|
||||
<Requests items={["cURL","JavaScript","Go"]}>
|
||||
|
||||
<Request value={"cURL"}>
|
||||
|
||||
@@ -282,18 +338,47 @@ curl -X GET "http://petstore.swagger.io/v1/pets/string"
|
||||
|
||||
```js
|
||||
fetch("http://petstore.swagger.io/v1/pets/string", {
|
||||
method: "GET"
|
||||
|
||||
});
|
||||
```
|
||||
|
||||
</Request>
|
||||
|
||||
<Request value={"Go"}>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
func main() {
|
||||
url := "http://petstore.swagger.io/v1/pets/string"
|
||||
|
||||
req, _ := http.NewRequest("GET", url, nil)
|
||||
|
||||
res, _ := http.DefaultClient.Do(req)
|
||||
defer res.Body.Close()
|
||||
body, _ := ioutil.ReadAll(res.Body)
|
||||
|
||||
fmt.Println(res)
|
||||
fmt.Println(string(body))
|
||||
}
|
||||
```
|
||||
|
||||
</Request>
|
||||
|
||||
</Requests>
|
||||
|
||||
<Responses items={["200","default"]}>
|
||||
|
||||
<Response value={"200"}>
|
||||
|
||||
Expected response to a valid request
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -326,6 +411,8 @@ export interface Response {
|
||||
|
||||
<Response value={"default"}>
|
||||
|
||||
unexpected error
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
|
||||
@@ -37,22 +37,11 @@ The id of the api to fetch
|
||||
|
||||
</Property>
|
||||
|
||||
| Status code | Description |
|
||||
| ----------- | ----------- |
|
||||
| `200` | The configuration for an api |
|
||||
| `400` | The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing). |
|
||||
| `401` | Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. |
|
||||
| `403` | The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401 Unauthorized, the client's identity is known to the server. |
|
||||
| `404` | The server cannot find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 Forbidden to hide the existence of a resource from an unauthorized client. This response code is probably the most well known due to its frequent occurrence on the web. |
|
||||
| `409` | This response is sent when a request conflicts with the current state of the server. |
|
||||
| `429` | The user has sent too many requests in a given amount of time ("rate limiting") |
|
||||
| `500` | The server has encountered a situation it does not know how to handle. |
|
||||
|
||||
</APIInfo>
|
||||
|
||||
<APIExample>
|
||||
|
||||
<Requests items={["cURL","JavaScript"]}>
|
||||
<Requests items={["cURL","JavaScript","Go"]}>
|
||||
|
||||
<Request value={"cURL"}>
|
||||
|
||||
@@ -66,18 +55,47 @@ curl -X GET "https://api.unkey.dev/v1/apis.getApi?apiId=api_1234"
|
||||
|
||||
```js
|
||||
fetch("https://api.unkey.dev/v1/apis.getApi?apiId=api_1234", {
|
||||
method: "GET"
|
||||
|
||||
});
|
||||
```
|
||||
|
||||
</Request>
|
||||
|
||||
<Request value={"Go"}>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
func main() {
|
||||
url := "https://api.unkey.dev/v1/apis.getApi?apiId=api_1234"
|
||||
|
||||
req, _ := http.NewRequest("GET", url, nil)
|
||||
|
||||
res, _ := http.DefaultClient.Do(req)
|
||||
defer res.Body.Close()
|
||||
body, _ := ioutil.ReadAll(res.Body)
|
||||
|
||||
fmt.Println(res)
|
||||
fmt.Println(string(body))
|
||||
}
|
||||
```
|
||||
|
||||
</Request>
|
||||
|
||||
</Requests>
|
||||
|
||||
<Responses items={["200","400","401","403","404","409","429","500"]}>
|
||||
|
||||
<Response value={"200"}>
|
||||
|
||||
The configuration for an api
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -119,6 +137,8 @@ export interface Response {
|
||||
|
||||
<Response value={"400"}>
|
||||
|
||||
The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -169,6 +189,8 @@ export interface Response {
|
||||
|
||||
<Response value={"401"}>
|
||||
|
||||
Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -219,6 +241,8 @@ export interface Response {
|
||||
|
||||
<Response value={"403"}>
|
||||
|
||||
The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401 Unauthorized, the client's identity is known to the server.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -269,6 +293,8 @@ export interface Response {
|
||||
|
||||
<Response value={"404"}>
|
||||
|
||||
The server cannot find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 Forbidden to hide the existence of a resource from an unauthorized client. This response code is probably the most well known due to its frequent occurrence on the web.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -319,6 +345,8 @@ export interface Response {
|
||||
|
||||
<Response value={"409"}>
|
||||
|
||||
This response is sent when a request conflicts with the current state of the server.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -369,6 +397,8 @@ export interface Response {
|
||||
|
||||
<Response value={"429"}>
|
||||
|
||||
The user has sent too many requests in a given amount of time ("rate limiting")
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -419,6 +449,8 @@ export interface Response {
|
||||
|
||||
<Response value={"500"}>
|
||||
|
||||
The server has encountered a situation it does not know how to handle.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -503,22 +535,11 @@ The name for your API. This is not customer facing.
|
||||
|
||||
</Property>
|
||||
|
||||
| Status code | Description |
|
||||
| ----------- | ----------- |
|
||||
| `200` | The configuration for an api |
|
||||
| `400` | The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing). |
|
||||
| `401` | Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. |
|
||||
| `403` | The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401 Unauthorized, the client's identity is known to the server. |
|
||||
| `404` | The server cannot find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 Forbidden to hide the existence of a resource from an unauthorized client. This response code is probably the most well known due to its frequent occurrence on the web. |
|
||||
| `409` | This response is sent when a request conflicts with the current state of the server. |
|
||||
| `429` | The user has sent too many requests in a given amount of time ("rate limiting") |
|
||||
| `500` | The server has encountered a situation it does not know how to handle. |
|
||||
|
||||
</APIInfo>
|
||||
|
||||
<APIExample>
|
||||
|
||||
<Requests items={["cURL","JavaScript"]}>
|
||||
<Requests items={["cURL","JavaScript","Go"]}>
|
||||
|
||||
<Request value={"cURL"}>
|
||||
|
||||
@@ -536,7 +557,6 @@ curl -X POST "https://api.unkey.dev/v1/apis.createApi" \
|
||||
|
||||
```js
|
||||
fetch("https://api.unkey.dev/v1/apis.createApi", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
"name": "my-api"
|
||||
})
|
||||
@@ -545,12 +565,45 @@ fetch("https://api.unkey.dev/v1/apis.createApi", {
|
||||
|
||||
</Request>
|
||||
|
||||
<Request value={"Go"}>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
url := "https://api.unkey.dev/v1/apis.createApi"
|
||||
payload := strings.NewReader(`{
|
||||
"name": "my-api"
|
||||
}`)
|
||||
|
||||
req, _ := http.NewRequest("POST", url, payload)
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
res, _ := http.DefaultClient.Do(req)
|
||||
defer res.Body.Close()
|
||||
body, _ := ioutil.ReadAll(res.Body)
|
||||
|
||||
fmt.Println(res)
|
||||
fmt.Println(string(body))
|
||||
}
|
||||
```
|
||||
|
||||
</Request>
|
||||
|
||||
</Requests>
|
||||
|
||||
<Responses items={["200","400","401","403","404","409","429","500"]}>
|
||||
|
||||
<Response value={"200"}>
|
||||
|
||||
The configuration for an api
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -582,6 +635,8 @@ export interface Response {
|
||||
|
||||
<Response value={"400"}>
|
||||
|
||||
The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -632,6 +687,8 @@ export interface Response {
|
||||
|
||||
<Response value={"401"}>
|
||||
|
||||
Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -682,6 +739,8 @@ export interface Response {
|
||||
|
||||
<Response value={"403"}>
|
||||
|
||||
The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401 Unauthorized, the client's identity is known to the server.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -732,6 +791,8 @@ export interface Response {
|
||||
|
||||
<Response value={"404"}>
|
||||
|
||||
The server cannot find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 Forbidden to hide the existence of a resource from an unauthorized client. This response code is probably the most well known due to its frequent occurrence on the web.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -782,6 +843,8 @@ export interface Response {
|
||||
|
||||
<Response value={"409"}>
|
||||
|
||||
This response is sent when a request conflicts with the current state of the server.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -832,6 +895,8 @@ export interface Response {
|
||||
|
||||
<Response value={"429"}>
|
||||
|
||||
The user has sent too many requests in a given amount of time ("rate limiting")
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -882,6 +947,8 @@ export interface Response {
|
||||
|
||||
<Response value={"500"}>
|
||||
|
||||
The server has encountered a situation it does not know how to handle.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -994,22 +1061,11 @@ If provided, this will only return keys where the `ownerId` matches.
|
||||
|
||||
</Property>
|
||||
|
||||
| Status code | Description |
|
||||
| ----------- | ----------- |
|
||||
| `200` | The configuration for an api |
|
||||
| `400` | The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing). |
|
||||
| `401` | Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. |
|
||||
| `403` | The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401 Unauthorized, the client's identity is known to the server. |
|
||||
| `404` | The server cannot find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 Forbidden to hide the existence of a resource from an unauthorized client. This response code is probably the most well known due to its frequent occurrence on the web. |
|
||||
| `409` | This response is sent when a request conflicts with the current state of the server. |
|
||||
| `429` | The user has sent too many requests in a given amount of time ("rate limiting") |
|
||||
| `500` | The server has encountered a situation it does not know how to handle. |
|
||||
|
||||
</APIInfo>
|
||||
|
||||
<APIExample>
|
||||
|
||||
<Requests items={["cURL","JavaScript"]}>
|
||||
<Requests items={["cURL","JavaScript","Go"]}>
|
||||
|
||||
<Request value={"cURL"}>
|
||||
|
||||
@@ -1023,18 +1079,47 @@ curl -X GET "https://api.unkey.dev/v1/apis.listKeys?apiId=api_1234&limit=100&cur
|
||||
|
||||
```js
|
||||
fetch("https://api.unkey.dev/v1/apis.listKeys?apiId=api_1234&limit=100&cursor=string&ownerId=string", {
|
||||
method: "GET"
|
||||
|
||||
});
|
||||
```
|
||||
|
||||
</Request>
|
||||
|
||||
<Request value={"Go"}>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
func main() {
|
||||
url := "https://api.unkey.dev/v1/apis.listKeys?apiId=api_1234&limit=100&cursor=string&ownerId=string"
|
||||
|
||||
req, _ := http.NewRequest("GET", url, nil)
|
||||
|
||||
res, _ := http.DefaultClient.Do(req)
|
||||
defer res.Body.Close()
|
||||
body, _ := ioutil.ReadAll(res.Body)
|
||||
|
||||
fmt.Println(res)
|
||||
fmt.Println(string(body))
|
||||
}
|
||||
```
|
||||
|
||||
</Request>
|
||||
|
||||
</Requests>
|
||||
|
||||
<Responses items={["200","400","401","403","404","409","429","500"]}>
|
||||
|
||||
<Response value={"200"}>
|
||||
|
||||
The configuration for an api
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -1203,6 +1288,8 @@ export interface Response {
|
||||
|
||||
<Response value={"400"}>
|
||||
|
||||
The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -1253,6 +1340,8 @@ export interface Response {
|
||||
|
||||
<Response value={"401"}>
|
||||
|
||||
Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -1303,6 +1392,8 @@ export interface Response {
|
||||
|
||||
<Response value={"403"}>
|
||||
|
||||
The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401 Unauthorized, the client's identity is known to the server.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -1353,6 +1444,8 @@ export interface Response {
|
||||
|
||||
<Response value={"404"}>
|
||||
|
||||
The server cannot find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 Forbidden to hide the existence of a resource from an unauthorized client. This response code is probably the most well known due to its frequent occurrence on the web.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -1403,6 +1496,8 @@ export interface Response {
|
||||
|
||||
<Response value={"409"}>
|
||||
|
||||
This response is sent when a request conflicts with the current state of the server.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -1453,6 +1548,8 @@ export interface Response {
|
||||
|
||||
<Response value={"429"}>
|
||||
|
||||
The user has sent too many requests in a given amount of time ("rate limiting")
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -1503,6 +1600,8 @@ export interface Response {
|
||||
|
||||
<Response value={"500"}>
|
||||
|
||||
The server has encountered a situation it does not know how to handle.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -1587,22 +1686,11 @@ The id of the api to delete
|
||||
|
||||
</Property>
|
||||
|
||||
| Status code | Description |
|
||||
| ----------- | ----------- |
|
||||
| `200` | The api was successfully deleted, it may take up to 30s for this to take effect in all regions |
|
||||
| `400` | The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing). |
|
||||
| `401` | Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. |
|
||||
| `403` | The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401 Unauthorized, the client's identity is known to the server. |
|
||||
| `404` | The server cannot find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 Forbidden to hide the existence of a resource from an unauthorized client. This response code is probably the most well known due to its frequent occurrence on the web. |
|
||||
| `409` | This response is sent when a request conflicts with the current state of the server. |
|
||||
| `429` | The user has sent too many requests in a given amount of time ("rate limiting") |
|
||||
| `500` | The server has encountered a situation it does not know how to handle. |
|
||||
|
||||
</APIInfo>
|
||||
|
||||
<APIExample>
|
||||
|
||||
<Requests items={["cURL","JavaScript"]}>
|
||||
<Requests items={["cURL","JavaScript","Go"]}>
|
||||
|
||||
<Request value={"cURL"}>
|
||||
|
||||
@@ -1620,7 +1708,6 @@ curl -X POST "https://api.unkey.dev/v1/apis.deleteApi" \
|
||||
|
||||
```js
|
||||
fetch("https://api.unkey.dev/v1/apis.deleteApi", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
"apiId": "api_1234"
|
||||
})
|
||||
@@ -1629,12 +1716,45 @@ fetch("https://api.unkey.dev/v1/apis.deleteApi", {
|
||||
|
||||
</Request>
|
||||
|
||||
<Request value={"Go"}>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
url := "https://api.unkey.dev/v1/apis.deleteApi"
|
||||
payload := strings.NewReader(`{
|
||||
"apiId": "api_1234"
|
||||
}`)
|
||||
|
||||
req, _ := http.NewRequest("POST", url, payload)
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
res, _ := http.DefaultClient.Do(req)
|
||||
defer res.Body.Close()
|
||||
body, _ := ioutil.ReadAll(res.Body)
|
||||
|
||||
fmt.Println(res)
|
||||
fmt.Println(string(body))
|
||||
}
|
||||
```
|
||||
|
||||
</Request>
|
||||
|
||||
</Requests>
|
||||
|
||||
<Responses items={["200","400","401","403","404","409","429","500"]}>
|
||||
|
||||
<Response value={"200"}>
|
||||
|
||||
The api was successfully deleted, it may take up to 30s for this to take effect in all regions
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -1659,6 +1779,8 @@ export interface Response {}
|
||||
|
||||
<Response value={"400"}>
|
||||
|
||||
The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -1709,6 +1831,8 @@ export interface Response {
|
||||
|
||||
<Response value={"401"}>
|
||||
|
||||
Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -1759,6 +1883,8 @@ export interface Response {
|
||||
|
||||
<Response value={"403"}>
|
||||
|
||||
The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401 Unauthorized, the client's identity is known to the server.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -1809,6 +1935,8 @@ export interface Response {
|
||||
|
||||
<Response value={"404"}>
|
||||
|
||||
The server cannot find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 Forbidden to hide the existence of a resource from an unauthorized client. This response code is probably the most well known due to its frequent occurrence on the web.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -1859,6 +1987,8 @@ export interface Response {
|
||||
|
||||
<Response value={"409"}>
|
||||
|
||||
This response is sent when a request conflicts with the current state of the server.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -1909,6 +2039,8 @@ export interface Response {
|
||||
|
||||
<Response value={"429"}>
|
||||
|
||||
The user has sent too many requests in a given amount of time ("rate limiting")
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -1959,6 +2091,8 @@ export interface Response {
|
||||
|
||||
<Response value={"500"}>
|
||||
|
||||
The server has encountered a situation it does not know how to handle.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
|
||||
@@ -37,22 +37,11 @@ The id of the key to fetch
|
||||
|
||||
</Property>
|
||||
|
||||
| Status code | Description |
|
||||
| ----------- | ----------- |
|
||||
| `200` | The configuration for a single key |
|
||||
| `400` | The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing). |
|
||||
| `401` | Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. |
|
||||
| `403` | The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401 Unauthorized, the client's identity is known to the server. |
|
||||
| `404` | The server cannot find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 Forbidden to hide the existence of a resource from an unauthorized client. This response code is probably the most well known due to its frequent occurrence on the web. |
|
||||
| `409` | This response is sent when a request conflicts with the current state of the server. |
|
||||
| `429` | The user has sent too many requests in a given amount of time ("rate limiting") |
|
||||
| `500` | The server has encountered a situation it does not know how to handle. |
|
||||
|
||||
</APIInfo>
|
||||
|
||||
<APIExample>
|
||||
|
||||
<Requests items={["cURL","JavaScript"]}>
|
||||
<Requests items={["cURL","JavaScript","Go"]}>
|
||||
|
||||
<Request value={"cURL"}>
|
||||
|
||||
@@ -66,18 +55,47 @@ curl -X GET "https://api.unkey.dev/v1/keys.getKey?keyId=key_1234"
|
||||
|
||||
```js
|
||||
fetch("https://api.unkey.dev/v1/keys.getKey?keyId=key_1234", {
|
||||
method: "GET"
|
||||
|
||||
});
|
||||
```
|
||||
|
||||
</Request>
|
||||
|
||||
<Request value={"Go"}>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
func main() {
|
||||
url := "https://api.unkey.dev/v1/keys.getKey?keyId=key_1234"
|
||||
|
||||
req, _ := http.NewRequest("GET", url, nil)
|
||||
|
||||
res, _ := http.DefaultClient.Do(req)
|
||||
defer res.Body.Close()
|
||||
body, _ := ioutil.ReadAll(res.Body)
|
||||
|
||||
fmt.Println(res)
|
||||
fmt.Println(string(body))
|
||||
}
|
||||
```
|
||||
|
||||
</Request>
|
||||
|
||||
</Requests>
|
||||
|
||||
<Responses items={["200","400","401","403","404","409","429","500"]}>
|
||||
|
||||
<Response value={"200"}>
|
||||
|
||||
The configuration for a single key
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -230,6 +248,8 @@ export interface Response {
|
||||
|
||||
<Response value={"400"}>
|
||||
|
||||
The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -280,6 +300,8 @@ export interface Response {
|
||||
|
||||
<Response value={"401"}>
|
||||
|
||||
Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -330,6 +352,8 @@ export interface Response {
|
||||
|
||||
<Response value={"403"}>
|
||||
|
||||
The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401 Unauthorized, the client's identity is known to the server.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -380,6 +404,8 @@ export interface Response {
|
||||
|
||||
<Response value={"404"}>
|
||||
|
||||
The server cannot find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 Forbidden to hide the existence of a resource from an unauthorized client. This response code is probably the most well known due to its frequent occurrence on the web.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -430,6 +456,8 @@ export interface Response {
|
||||
|
||||
<Response value={"409"}>
|
||||
|
||||
This response is sent when a request conflicts with the current state of the server.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -480,6 +508,8 @@ export interface Response {
|
||||
|
||||
<Response value={"429"}>
|
||||
|
||||
The user has sent too many requests in a given amount of time ("rate limiting")
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -530,6 +560,8 @@ export interface Response {
|
||||
|
||||
<Response value={"500"}>
|
||||
|
||||
The server has encountered a situation it does not know how to handle.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -614,22 +646,11 @@ The id of the key to revoke
|
||||
|
||||
</Property>
|
||||
|
||||
| Status code | Description |
|
||||
| ----------- | ----------- |
|
||||
| `200` | The key was successfully revoked, it may take up to 30s for this to take effect in all regions |
|
||||
| `400` | The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing). |
|
||||
| `401` | Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. |
|
||||
| `403` | The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401 Unauthorized, the client's identity is known to the server. |
|
||||
| `404` | The server cannot find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 Forbidden to hide the existence of a resource from an unauthorized client. This response code is probably the most well known due to its frequent occurrence on the web. |
|
||||
| `409` | This response is sent when a request conflicts with the current state of the server. |
|
||||
| `429` | The user has sent too many requests in a given amount of time ("rate limiting") |
|
||||
| `500` | The server has encountered a situation it does not know how to handle. |
|
||||
|
||||
</APIInfo>
|
||||
|
||||
<APIExample>
|
||||
|
||||
<Requests items={["cURL","JavaScript"]}>
|
||||
<Requests items={["cURL","JavaScript","Go"]}>
|
||||
|
||||
<Request value={"cURL"}>
|
||||
|
||||
@@ -647,7 +668,6 @@ curl -X POST "https://api.unkey.dev/v1/keys.deleteKey" \
|
||||
|
||||
```js
|
||||
fetch("https://api.unkey.dev/v1/keys.deleteKey", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
"keyId": "key_1234"
|
||||
})
|
||||
@@ -656,12 +676,45 @@ fetch("https://api.unkey.dev/v1/keys.deleteKey", {
|
||||
|
||||
</Request>
|
||||
|
||||
<Request value={"Go"}>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
url := "https://api.unkey.dev/v1/keys.deleteKey"
|
||||
payload := strings.NewReader(`{
|
||||
"keyId": "key_1234"
|
||||
}`)
|
||||
|
||||
req, _ := http.NewRequest("POST", url, payload)
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
res, _ := http.DefaultClient.Do(req)
|
||||
defer res.Body.Close()
|
||||
body, _ := ioutil.ReadAll(res.Body)
|
||||
|
||||
fmt.Println(res)
|
||||
fmt.Println(string(body))
|
||||
}
|
||||
```
|
||||
|
||||
</Request>
|
||||
|
||||
</Requests>
|
||||
|
||||
<Responses items={["200","400","401","403","404","409","429","500"]}>
|
||||
|
||||
<Response value={"200"}>
|
||||
|
||||
The key was successfully revoked, it may take up to 30s for this to take effect in all regions
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -686,6 +739,8 @@ export interface Response {}
|
||||
|
||||
<Response value={"400"}>
|
||||
|
||||
The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -736,6 +791,8 @@ export interface Response {
|
||||
|
||||
<Response value={"401"}>
|
||||
|
||||
Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -786,6 +843,8 @@ export interface Response {
|
||||
|
||||
<Response value={"403"}>
|
||||
|
||||
The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401 Unauthorized, the client's identity is known to the server.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -836,6 +895,8 @@ export interface Response {
|
||||
|
||||
<Response value={"404"}>
|
||||
|
||||
The server cannot find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 Forbidden to hide the existence of a resource from an unauthorized client. This response code is probably the most well known due to its frequent occurrence on the web.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -886,6 +947,8 @@ export interface Response {
|
||||
|
||||
<Response value={"409"}>
|
||||
|
||||
This response is sent when a request conflicts with the current state of the server.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -936,6 +999,8 @@ export interface Response {
|
||||
|
||||
<Response value={"429"}>
|
||||
|
||||
The user has sent too many requests in a given amount of time ("rate limiting")
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -986,6 +1051,8 @@ export interface Response {
|
||||
|
||||
<Response value={"500"}>
|
||||
|
||||
The server has encountered a situation it does not know how to handle.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -1234,22 +1301,11 @@ Sets if key is enabled or disabled. Disabled keys are not valid.
|
||||
|
||||
</Property>
|
||||
|
||||
| Status code | Description |
|
||||
| ----------- | ----------- |
|
||||
| `200` | The configuration for an api |
|
||||
| `400` | The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing). |
|
||||
| `401` | Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. |
|
||||
| `403` | The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401 Unauthorized, the client's identity is known to the server. |
|
||||
| `404` | The server cannot find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 Forbidden to hide the existence of a resource from an unauthorized client. This response code is probably the most well known due to its frequent occurrence on the web. |
|
||||
| `409` | This response is sent when a request conflicts with the current state of the server. |
|
||||
| `429` | The user has sent too many requests in a given amount of time ("rate limiting") |
|
||||
| `500` | The server has encountered a situation it does not know how to handle. |
|
||||
|
||||
</APIInfo>
|
||||
|
||||
<APIExample>
|
||||
|
||||
<Requests items={["cURL","JavaScript"]}>
|
||||
<Requests items={["cURL","JavaScript","Go"]}>
|
||||
|
||||
<Request value={"cURL"}>
|
||||
|
||||
@@ -1292,7 +1348,6 @@ curl -X POST "https://api.unkey.dev/v1/keys.createKey" \
|
||||
|
||||
```js
|
||||
fetch("https://api.unkey.dev/v1/keys.createKey", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
"apiId": "api_123",
|
||||
"prefix": "string",
|
||||
@@ -1326,12 +1381,70 @@ fetch("https://api.unkey.dev/v1/keys.createKey", {
|
||||
|
||||
</Request>
|
||||
|
||||
<Request value={"Go"}>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
url := "https://api.unkey.dev/v1/keys.createKey"
|
||||
payload := strings.NewReader(`{
|
||||
"apiId": "api_123",
|
||||
"prefix": "string",
|
||||
"name": "my key",
|
||||
"byteLength": 16,
|
||||
"ownerId": "team_123",
|
||||
"meta": {
|
||||
"billingTier": "PRO",
|
||||
"trialEnds": "2023-06-16T17:16:37.161Z"
|
||||
},
|
||||
"roles": [
|
||||
"admin",
|
||||
"finance"
|
||||
],
|
||||
"expires": 1623869797161,
|
||||
"remaining": 1000,
|
||||
"refill": {
|
||||
"interval": "daily",
|
||||
"amount": 100
|
||||
},
|
||||
"ratelimit": {
|
||||
"type": "fast",
|
||||
"limit": 10,
|
||||
"refillRate": 1,
|
||||
"refillInterval": 60
|
||||
},
|
||||
"enabled": false
|
||||
}`)
|
||||
|
||||
req, _ := http.NewRequest("POST", url, payload)
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
res, _ := http.DefaultClient.Do(req)
|
||||
defer res.Body.Close()
|
||||
body, _ := ioutil.ReadAll(res.Body)
|
||||
|
||||
fmt.Println(res)
|
||||
fmt.Println(string(body))
|
||||
}
|
||||
```
|
||||
|
||||
</Request>
|
||||
|
||||
</Requests>
|
||||
|
||||
<Responses items={["200","400","401","403","404","409","429","500"]}>
|
||||
|
||||
<Response value={"200"}>
|
||||
|
||||
The configuration for an api
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -1368,6 +1481,8 @@ export interface Response {
|
||||
|
||||
<Response value={"400"}>
|
||||
|
||||
The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -1418,6 +1533,8 @@ export interface Response {
|
||||
|
||||
<Response value={"401"}>
|
||||
|
||||
Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -1468,6 +1585,8 @@ export interface Response {
|
||||
|
||||
<Response value={"403"}>
|
||||
|
||||
The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401 Unauthorized, the client's identity is known to the server.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -1518,6 +1637,8 @@ export interface Response {
|
||||
|
||||
<Response value={"404"}>
|
||||
|
||||
The server cannot find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 Forbidden to hide the existence of a resource from an unauthorized client. This response code is probably the most well known due to its frequent occurrence on the web.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -1568,6 +1689,8 @@ export interface Response {
|
||||
|
||||
<Response value={"409"}>
|
||||
|
||||
This response is sent when a request conflicts with the current state of the server.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -1618,6 +1741,8 @@ export interface Response {
|
||||
|
||||
<Response value={"429"}>
|
||||
|
||||
The user has sent too many requests in a given amount of time ("rate limiting")
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -1668,6 +1793,8 @@ export interface Response {
|
||||
|
||||
<Response value={"500"}>
|
||||
|
||||
The server has encountered a situation it does not know how to handle.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -1753,22 +1880,11 @@ The key to verify
|
||||
|
||||
</Property>
|
||||
|
||||
| Status code | Description |
|
||||
| ----------- | ----------- |
|
||||
| `200` | The verification result |
|
||||
| `400` | The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing). |
|
||||
| `401` | Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. |
|
||||
| `403` | The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401 Unauthorized, the client's identity is known to the server. |
|
||||
| `404` | The server cannot find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 Forbidden to hide the existence of a resource from an unauthorized client. This response code is probably the most well known due to its frequent occurrence on the web. |
|
||||
| `409` | This response is sent when a request conflicts with the current state of the server. |
|
||||
| `429` | The user has sent too many requests in a given amount of time ("rate limiting") |
|
||||
| `500` | The server has encountered a situation it does not know how to handle. |
|
||||
|
||||
</APIInfo>
|
||||
|
||||
<APIExample>
|
||||
|
||||
<Requests items={["cURL","JavaScript"]}>
|
||||
<Requests items={["cURL","JavaScript","Go"]}>
|
||||
|
||||
<Request value={"cURL"}>
|
||||
|
||||
@@ -1787,7 +1903,6 @@ curl -X POST "https://api.unkey.dev/v1/keys.verifyKey" \
|
||||
|
||||
```js
|
||||
fetch("https://api.unkey.dev/v1/keys.verifyKey", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
"apiId": "api_1234",
|
||||
"key": "sk_1234"
|
||||
@@ -1797,12 +1912,46 @@ fetch("https://api.unkey.dev/v1/keys.verifyKey", {
|
||||
|
||||
</Request>
|
||||
|
||||
<Request value={"Go"}>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
url := "https://api.unkey.dev/v1/keys.verifyKey"
|
||||
payload := strings.NewReader(`{
|
||||
"apiId": "api_1234",
|
||||
"key": "sk_1234"
|
||||
}`)
|
||||
|
||||
req, _ := http.NewRequest("POST", url, payload)
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
res, _ := http.DefaultClient.Do(req)
|
||||
defer res.Body.Close()
|
||||
body, _ := ioutil.ReadAll(res.Body)
|
||||
|
||||
fmt.Println(res)
|
||||
fmt.Println(string(body))
|
||||
}
|
||||
```
|
||||
|
||||
</Request>
|
||||
|
||||
</Requests>
|
||||
|
||||
<Responses items={["200","400","401","403","404","409","429","500"]}>
|
||||
|
||||
<Response value={"200"}>
|
||||
|
||||
The verification result
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -1923,6 +2072,8 @@ export interface Response {
|
||||
|
||||
<Response value={"400"}>
|
||||
|
||||
The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -1973,6 +2124,8 @@ export interface Response {
|
||||
|
||||
<Response value={"401"}>
|
||||
|
||||
Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -2023,6 +2176,8 @@ export interface Response {
|
||||
|
||||
<Response value={"403"}>
|
||||
|
||||
The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401 Unauthorized, the client's identity is known to the server.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -2073,6 +2228,8 @@ export interface Response {
|
||||
|
||||
<Response value={"404"}>
|
||||
|
||||
The server cannot find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 Forbidden to hide the existence of a resource from an unauthorized client. This response code is probably the most well known due to its frequent occurrence on the web.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -2123,6 +2280,8 @@ export interface Response {
|
||||
|
||||
<Response value={"409"}>
|
||||
|
||||
This response is sent when a request conflicts with the current state of the server.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -2173,6 +2332,8 @@ export interface Response {
|
||||
|
||||
<Response value={"429"}>
|
||||
|
||||
The user has sent too many requests in a given amount of time ("rate limiting")
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -2223,6 +2384,8 @@ export interface Response {
|
||||
|
||||
<Response value={"500"}>
|
||||
|
||||
The server has encountered a situation it does not know how to handle.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -2433,22 +2596,11 @@ Set if key is enabled or disabled. If disabled, the key cannot be used to verify
|
||||
|
||||
</Property>
|
||||
|
||||
| Status code | Description |
|
||||
| ----------- | ----------- |
|
||||
| `200` | The key was successfully updated, it may take up to 30s for this to take effect in all regions |
|
||||
| `400` | The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing). |
|
||||
| `401` | Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. |
|
||||
| `403` | The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401 Unauthorized, the client's identity is known to the server. |
|
||||
| `404` | The server cannot find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 Forbidden to hide the existence of a resource from an unauthorized client. This response code is probably the most well known due to its frequent occurrence on the web. |
|
||||
| `409` | This response is sent when a request conflicts with the current state of the server. |
|
||||
| `429` | The user has sent too many requests in a given amount of time ("rate limiting") |
|
||||
| `500` | The server has encountered a situation it does not know how to handle. |
|
||||
|
||||
</APIInfo>
|
||||
|
||||
<APIExample>
|
||||
|
||||
<Requests items={["cURL","JavaScript"]}>
|
||||
<Requests items={["cURL","JavaScript","Go"]}>
|
||||
|
||||
<Request value={"cURL"}>
|
||||
|
||||
@@ -2488,7 +2640,6 @@ curl -X POST "https://api.unkey.dev/v1/keys.updateKey" \
|
||||
|
||||
```js
|
||||
fetch("https://api.unkey.dev/v1/keys.updateKey", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
"keyId": "key_123",
|
||||
"name": "Customer X",
|
||||
@@ -2519,12 +2670,67 @@ fetch("https://api.unkey.dev/v1/keys.updateKey", {
|
||||
|
||||
</Request>
|
||||
|
||||
<Request value={"Go"}>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
url := "https://api.unkey.dev/v1/keys.updateKey"
|
||||
payload := strings.NewReader(`{
|
||||
"keyId": "key_123",
|
||||
"name": "Customer X",
|
||||
"ownerId": "user_123",
|
||||
"meta": {
|
||||
"roles": [
|
||||
"admin",
|
||||
"user"
|
||||
],
|
||||
"stripeCustomerId": "cus_1234"
|
||||
},
|
||||
"expires": 0,
|
||||
"ratelimit": {
|
||||
"type": "fast",
|
||||
"limit": 10,
|
||||
"refillRate": 1,
|
||||
"refillInterval": 60
|
||||
},
|
||||
"remaining": 1000,
|
||||
"refill": {
|
||||
"interval": "daily",
|
||||
"amount": 100
|
||||
},
|
||||
"enabled": true
|
||||
}`)
|
||||
|
||||
req, _ := http.NewRequest("POST", url, payload)
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
res, _ := http.DefaultClient.Do(req)
|
||||
defer res.Body.Close()
|
||||
body, _ := ioutil.ReadAll(res.Body)
|
||||
|
||||
fmt.Println(res)
|
||||
fmt.Println(string(body))
|
||||
}
|
||||
```
|
||||
|
||||
</Request>
|
||||
|
||||
</Requests>
|
||||
|
||||
<Responses items={["200","400","401","403","404","409","429","500"]}>
|
||||
|
||||
<Response value={"200"}>
|
||||
|
||||
The key was successfully updated, it may take up to 30s for this to take effect in all regions
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -2549,6 +2755,8 @@ export interface Response {}
|
||||
|
||||
<Response value={"400"}>
|
||||
|
||||
The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -2599,6 +2807,8 @@ export interface Response {
|
||||
|
||||
<Response value={"401"}>
|
||||
|
||||
Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -2649,6 +2859,8 @@ export interface Response {
|
||||
|
||||
<Response value={"403"}>
|
||||
|
||||
The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401 Unauthorized, the client's identity is known to the server.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -2699,6 +2911,8 @@ export interface Response {
|
||||
|
||||
<Response value={"404"}>
|
||||
|
||||
The server cannot find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 Forbidden to hide the existence of a resource from an unauthorized client. This response code is probably the most well known due to its frequent occurrence on the web.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -2749,6 +2963,8 @@ export interface Response {
|
||||
|
||||
<Response value={"409"}>
|
||||
|
||||
This response is sent when a request conflicts with the current state of the server.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -2799,6 +3015,8 @@ export interface Response {
|
||||
|
||||
<Response value={"429"}>
|
||||
|
||||
The user has sent too many requests in a given amount of time ("rate limiting")
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -2849,6 +3067,8 @@ export interface Response {
|
||||
|
||||
<Response value={"500"}>
|
||||
|
||||
The server has encountered a situation it does not know how to handle.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -2947,22 +3167,11 @@ The value you want to set, add or subtract the remaining count by
|
||||
|
||||
</Property>
|
||||
|
||||
| Status code | Description |
|
||||
| ----------- | ----------- |
|
||||
| `200` | The configuration for an api |
|
||||
| `400` | The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing). |
|
||||
| `401` | Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. |
|
||||
| `403` | The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401 Unauthorized, the client's identity is known to the server. |
|
||||
| `404` | The server cannot find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 Forbidden to hide the existence of a resource from an unauthorized client. This response code is probably the most well known due to its frequent occurrence on the web. |
|
||||
| `409` | This response is sent when a request conflicts with the current state of the server. |
|
||||
| `429` | The user has sent too many requests in a given amount of time ("rate limiting") |
|
||||
| `500` | The server has encountered a situation it does not know how to handle. |
|
||||
|
||||
</APIInfo>
|
||||
|
||||
<APIExample>
|
||||
|
||||
<Requests items={["cURL","JavaScript"]}>
|
||||
<Requests items={["cURL","JavaScript","Go"]}>
|
||||
|
||||
<Request value={"cURL"}>
|
||||
|
||||
@@ -2982,7 +3191,6 @@ curl -X POST "https://api.unkey.dev/v1/keys.updateRemaining" \
|
||||
|
||||
```js
|
||||
fetch("https://api.unkey.dev/v1/keys.updateRemaining", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
"keyId": "key_123",
|
||||
"op": "increment",
|
||||
@@ -2993,12 +3201,47 @@ fetch("https://api.unkey.dev/v1/keys.updateRemaining", {
|
||||
|
||||
</Request>
|
||||
|
||||
<Request value={"Go"}>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
url := "https://api.unkey.dev/v1/keys.updateRemaining"
|
||||
payload := strings.NewReader(`{
|
||||
"keyId": "key_123",
|
||||
"op": "increment",
|
||||
"value": 1
|
||||
}`)
|
||||
|
||||
req, _ := http.NewRequest("POST", url, payload)
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
res, _ := http.DefaultClient.Do(req)
|
||||
defer res.Body.Close()
|
||||
body, _ := ioutil.ReadAll(res.Body)
|
||||
|
||||
fmt.Println(res)
|
||||
fmt.Println(string(body))
|
||||
}
|
||||
```
|
||||
|
||||
</Request>
|
||||
|
||||
</Requests>
|
||||
|
||||
<Responses items={["200","400","401","403","404","409","429","500"]}>
|
||||
|
||||
<Response value={"200"}>
|
||||
|
||||
The configuration for an api
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -3030,6 +3273,8 @@ export interface Response {
|
||||
|
||||
<Response value={"400"}>
|
||||
|
||||
The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -3080,6 +3325,8 @@ export interface Response {
|
||||
|
||||
<Response value={"401"}>
|
||||
|
||||
Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -3130,6 +3377,8 @@ export interface Response {
|
||||
|
||||
<Response value={"403"}>
|
||||
|
||||
The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401 Unauthorized, the client's identity is known to the server.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -3180,6 +3429,8 @@ export interface Response {
|
||||
|
||||
<Response value={"404"}>
|
||||
|
||||
The server cannot find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 Forbidden to hide the existence of a resource from an unauthorized client. This response code is probably the most well known due to its frequent occurrence on the web.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -3230,6 +3481,8 @@ export interface Response {
|
||||
|
||||
<Response value={"409"}>
|
||||
|
||||
This response is sent when a request conflicts with the current state of the server.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -3280,6 +3533,8 @@ export interface Response {
|
||||
|
||||
<Response value={"429"}>
|
||||
|
||||
The user has sent too many requests in a given amount of time ("rate limiting")
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -3330,6 +3585,8 @@ export interface Response {
|
||||
|
||||
<Response value={"500"}>
|
||||
|
||||
The server has encountered a situation it does not know how to handle.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -3448,22 +3705,11 @@ The granularity of the usage data to fetch, currently only `day` is supported
|
||||
|
||||
</Property>
|
||||
|
||||
| Status code | Description |
|
||||
| ----------- | ----------- |
|
||||
| `200` | The configuration for a single key |
|
||||
| `400` | The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing). |
|
||||
| `401` | Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. |
|
||||
| `403` | The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401 Unauthorized, the client's identity is known to the server. |
|
||||
| `404` | The server cannot find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 Forbidden to hide the existence of a resource from an unauthorized client. This response code is probably the most well known due to its frequent occurrence on the web. |
|
||||
| `409` | This response is sent when a request conflicts with the current state of the server. |
|
||||
| `429` | The user has sent too many requests in a given amount of time ("rate limiting") |
|
||||
| `500` | The server has encountered a situation it does not know how to handle. |
|
||||
|
||||
</APIInfo>
|
||||
|
||||
<APIExample>
|
||||
|
||||
<Requests items={["cURL","JavaScript"]}>
|
||||
<Requests items={["cURL","JavaScript","Go"]}>
|
||||
|
||||
<Request value={"cURL"}>
|
||||
|
||||
@@ -3477,18 +3723,47 @@ curl -X GET "https://api.unkey.dev/v1/keys.getVerifications?keyId=key_1234&owner
|
||||
|
||||
```js
|
||||
fetch("https://api.unkey.dev/v1/keys.getVerifications?keyId=key_1234&ownerId=chronark&start=1620000000000&end=1620000000000&granularity=day", {
|
||||
method: "GET"
|
||||
|
||||
});
|
||||
```
|
||||
|
||||
</Request>
|
||||
|
||||
<Request value={"Go"}>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
func main() {
|
||||
url := "https://api.unkey.dev/v1/keys.getVerifications?keyId=key_1234&ownerId=chronark&start=1620000000000&end=1620000000000&granularity=day"
|
||||
|
||||
req, _ := http.NewRequest("GET", url, nil)
|
||||
|
||||
res, _ := http.DefaultClient.Do(req)
|
||||
defer res.Body.Close()
|
||||
body, _ := ioutil.ReadAll(res.Body)
|
||||
|
||||
fmt.Println(res)
|
||||
fmt.Println(string(body))
|
||||
}
|
||||
```
|
||||
|
||||
</Request>
|
||||
|
||||
</Requests>
|
||||
|
||||
<Responses items={["200","400","401","403","404","409","429","500"]}>
|
||||
|
||||
<Response value={"200"}>
|
||||
|
||||
The configuration for a single key
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -3541,6 +3816,8 @@ export interface Response {
|
||||
|
||||
<Response value={"400"}>
|
||||
|
||||
The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -3591,6 +3868,8 @@ export interface Response {
|
||||
|
||||
<Response value={"401"}>
|
||||
|
||||
Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -3641,6 +3920,8 @@ export interface Response {
|
||||
|
||||
<Response value={"403"}>
|
||||
|
||||
The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401 Unauthorized, the client's identity is known to the server.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -3691,6 +3972,8 @@ export interface Response {
|
||||
|
||||
<Response value={"404"}>
|
||||
|
||||
The server cannot find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 Forbidden to hide the existence of a resource from an unauthorized client. This response code is probably the most well known due to its frequent occurrence on the web.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -3741,6 +4024,8 @@ export interface Response {
|
||||
|
||||
<Response value={"409"}>
|
||||
|
||||
This response is sent when a request conflicts with the current state of the server.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -3791,6 +4076,8 @@ export interface Response {
|
||||
|
||||
<Response value={"429"}>
|
||||
|
||||
The user has sent too many requests in a given amount of time ("rate limiting")
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -3841,6 +4128,8 @@ export interface Response {
|
||||
|
||||
<Response value={"500"}>
|
||||
|
||||
The server has encountered a situation it does not know how to handle.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
|
||||
@@ -17,22 +17,11 @@ import { Root, API, APIInfo, APIExample, Responses, Response, ResponseTypes, Exa
|
||||
|
||||
</APIPlayground>
|
||||
|
||||
| Status code | Description |
|
||||
| ----------- | ----------- |
|
||||
| `200` | The configured services and their status |
|
||||
| `400` | The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing). |
|
||||
| `401` | Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response. |
|
||||
| `403` | The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401 Unauthorized, the client's identity is known to the server. |
|
||||
| `404` | The server cannot find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 Forbidden to hide the existence of a resource from an unauthorized client. This response code is probably the most well known due to its frequent occurrence on the web. |
|
||||
| `409` | This response is sent when a request conflicts with the current state of the server. |
|
||||
| `429` | The user has sent too many requests in a given amount of time ("rate limiting") |
|
||||
| `500` | The server has encountered a situation it does not know how to handle. |
|
||||
|
||||
</APIInfo>
|
||||
|
||||
<APIExample>
|
||||
|
||||
<Requests items={["cURL","JavaScript"]}>
|
||||
<Requests items={["cURL","JavaScript","Go"]}>
|
||||
|
||||
<Request value={"cURL"}>
|
||||
|
||||
@@ -46,18 +35,47 @@ curl -X GET "https://api.unkey.dev/v1/liveness"
|
||||
|
||||
```js
|
||||
fetch("https://api.unkey.dev/v1/liveness", {
|
||||
method: "GET"
|
||||
|
||||
});
|
||||
```
|
||||
|
||||
</Request>
|
||||
|
||||
<Request value={"Go"}>
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
func main() {
|
||||
url := "https://api.unkey.dev/v1/liveness"
|
||||
|
||||
req, _ := http.NewRequest("GET", url, nil)
|
||||
|
||||
res, _ := http.DefaultClient.Do(req)
|
||||
defer res.Body.Close()
|
||||
body, _ := ioutil.ReadAll(res.Body)
|
||||
|
||||
fmt.Println(res)
|
||||
fmt.Println(string(body))
|
||||
}
|
||||
```
|
||||
|
||||
</Request>
|
||||
|
||||
</Requests>
|
||||
|
||||
<Responses items={["200","400","401","403","404","409","429","500"]}>
|
||||
|
||||
<Response value={"200"}>
|
||||
|
||||
The configured services and their status
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -118,6 +136,8 @@ export interface Response {
|
||||
|
||||
<Response value={"400"}>
|
||||
|
||||
The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -168,6 +188,8 @@ export interface Response {
|
||||
|
||||
<Response value={"401"}>
|
||||
|
||||
Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -218,6 +240,8 @@ export interface Response {
|
||||
|
||||
<Response value={"403"}>
|
||||
|
||||
The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401 Unauthorized, the client's identity is known to the server.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -268,6 +292,8 @@ export interface Response {
|
||||
|
||||
<Response value={"404"}>
|
||||
|
||||
The server cannot find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 Forbidden to hide the existence of a resource from an unauthorized client. This response code is probably the most well known due to its frequent occurrence on the web.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -318,6 +344,8 @@ export interface Response {
|
||||
|
||||
<Response value={"409"}>
|
||||
|
||||
This response is sent when a request conflicts with the current state of the server.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -368,6 +396,8 @@ export interface Response {
|
||||
|
||||
<Response value={"429"}>
|
||||
|
||||
The user has sent too many requests in a given amount of time ("rate limiting")
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
@@ -418,6 +448,8 @@ export interface Response {
|
||||
|
||||
<Response value={"500"}>
|
||||
|
||||
The server has encountered a situation it does not know how to handle.
|
||||
|
||||
<ResponseTypes>
|
||||
|
||||
<ExampleResponse>
|
||||
|
||||
Reference in New Issue
Block a user