Create Streams API.
curl --request POST \
--url https://{tenant}/api/apis/streams \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: <content-type>' \
--data '{
"components": {
"securitySchemes": {
"bearerAuth": {
"description": "The API Access Credentials",
"scheme": "bearer",
"type": "http"
}
}
},
"info": {
"description": "This is a sample Streams API.",
"title": "Streams Sample",
"version": "1.0.0"
},
"openapi": "3.0.3",
"paths": {
"/api/sample/users": {
"get": {
"operationId": "getUsersSample",
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"items": {
"properties": {
"name": {
"type": "string"
}
},
"type": "object"
},
"type": "array"
}
}
},
"description": "fetched users"
}
},
"summary": "Get users",
"tags": [
"users"
]
}
}
},
"security": [
{
"bearerAuth": []
}
],
"servers": [
{
"url": "https://localhost:8080"
}
],
"x-tyk-api-gateway": {
"info": {
"name": "user",
"state": {
"active": true
}
},
"server": {
"listenPath": {
"strip": true,
"value": "/user-test-six/"
}
},
"upstream": {
"url": "https://localhost:8080"
}
},
"x-tyk-streaming": {
"streams": {
"stream1": {
"input": {
"kafka": {
"addresses": [
"localhost:9093"
],
"auto_replay_nacks": true,
"checkpoint_limit": 1024,
"consumer_group": "group1",
"target_version": "3.3.0",
"topics": [
"instrument.json.AMZN",
"instrument.json.GOOG"
]
}
},
"output": {
"broker": {
"outputs": [
{
"stdout": {
"codec": "lines"
}
},
{
"http_server": {
"allowed_verbs": [
"GET"
],
"path": "/one",
"stream_path": "/sse",
"ws_path": "/ws"
}
}
],
"pattern": "fan_out"
}
}
}
}
}
}'import requests
url = "https://{tenant}/api/apis/streams"
payload = "{\n \"components\": {\n \"securitySchemes\": {\n \"bearerAuth\": {\n \"description\": \"The API Access Credentials\",\n \"scheme\": \"bearer\",\n \"type\": \"http\"\n }\n }\n },\n \"info\": {\n \"description\": \"This is a sample Streams API.\",\n \"title\": \"Streams Sample\",\n \"version\": \"1.0.0\"\n },\n \"openapi\": \"3.0.3\",\n \"paths\": {\n \"/api/sample/users\": {\n \"get\": {\n \"operationId\": \"getUsersSample\",\n \"responses\": {\n \"200\": {\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"items\": {\n \"properties\": {\n \"name\": {\n \"type\": \"string\"\n }\n },\n \"type\": \"object\"\n },\n \"type\": \"array\"\n }\n }\n },\n \"description\": \"fetched users\"\n }\n },\n \"summary\": \"Get users\",\n \"tags\": [\n \"users\"\n ]\n }\n }\n },\n \"security\": [\n {\n \"bearerAuth\": []\n }\n ],\n \"servers\": [\n {\n \"url\": \"https://localhost:8080\"\n }\n ],\n \"x-tyk-api-gateway\": {\n \"info\": {\n \"name\": \"user\",\n \"state\": {\n \"active\": true\n }\n },\n \"server\": {\n \"listenPath\": {\n \"strip\": true,\n \"value\": \"/user-test-six/\"\n }\n },\n \"upstream\": {\n \"url\": \"https://localhost:8080\"\n }\n },\n \"x-tyk-streaming\": {\n \"streams\": {\n \"stream1\": {\n \"input\": {\n \"kafka\": {\n \"addresses\": [\n \"localhost:9093\"\n ],\n \"auto_replay_nacks\": true,\n \"checkpoint_limit\": 1024,\n \"consumer_group\": \"group1\",\n \"target_version\": \"3.3.0\",\n \"topics\": [\n \"instrument.json.AMZN\",\n \"instrument.json.GOOG\"\n ]\n }\n },\n \"output\": {\n \"broker\": {\n \"outputs\": [\n {\n \"stdout\": {\n \"codec\": \"lines\"\n }\n },\n {\n \"http_server\": {\n \"allowed_verbs\": [\n \"GET\"\n ],\n \"path\": \"/one\",\n \"stream_path\": \"/sse\",\n \"ws_path\": \"/ws\"\n }\n }\n ],\n \"pattern\": \"fan_out\"\n }\n }\n }\n }\n }\n}"
headers = {
"Content-Type": "<content-type>",
"Authorization": "Bearer <token>"
}
response = requests.post(url, data=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': '<content-type>', Authorization: 'Bearer <token>'},
body: '{\n "components": {\n "securitySchemes": {\n "bearerAuth": {\n "description": "The API Access Credentials",\n "scheme": "bearer",\n "type": "http"\n }\n }\n },\n "info": {\n "description": "This is a sample Streams API.",\n "title": "Streams Sample",\n "version": "1.0.0"\n },\n "openapi": "3.0.3",\n "paths": {\n "/api/sample/users": {\n "get": {\n "operationId": "getUsersSample",\n "responses": {\n "200": {\n "content": {\n "application/json": {\n "schema": {\n "items": {\n "properties": {\n "name": {\n "type": "string"\n }\n },\n "type": "object"\n },\n "type": "array"\n }\n }\n },\n "description": "fetched users"\n }\n },\n "summary": "Get users",\n "tags": [\n "users"\n ]\n }\n }\n },\n "security": [\n {\n "bearerAuth": []\n }\n ],\n "servers": [\n {\n "url": "https://localhost:8080"\n }\n ],\n "x-tyk-api-gateway": {\n "info": {\n "name": "user",\n "state": {\n "active": true\n }\n },\n "server": {\n "listenPath": {\n "strip": true,\n "value": "/user-test-six/"\n }\n },\n "upstream": {\n "url": "https://localhost:8080"\n }\n },\n "x-tyk-streaming": {\n "streams": {\n "stream1": {\n "input": {\n "kafka": {\n "addresses": [\n "localhost:9093"\n ],\n "auto_replay_nacks": true,\n "checkpoint_limit": 1024,\n "consumer_group": "group1",\n "target_version": "3.3.0",\n "topics": [\n "instrument.json.AMZN",\n "instrument.json.GOOG"\n ]\n }\n },\n "output": {\n "broker": {\n "outputs": [\n {\n "stdout": {\n "codec": "lines"\n }\n },\n {\n "http_server": {\n "allowed_verbs": [\n "GET"\n ],\n "path": "/one",\n "stream_path": "/sse",\n "ws_path": "/ws"\n }\n }\n ],\n "pattern": "fan_out"\n }\n }\n }\n }\n }\n}'
};
fetch('https://{tenant}/api/apis/streams', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{tenant}/api/apis/streams",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{\n \"components\": {\n \"securitySchemes\": {\n \"bearerAuth\": {\n \"description\": \"The API Access Credentials\",\n \"scheme\": \"bearer\",\n \"type\": \"http\"\n }\n }\n },\n \"info\": {\n \"description\": \"This is a sample Streams API.\",\n \"title\": \"Streams Sample\",\n \"version\": \"1.0.0\"\n },\n \"openapi\": \"3.0.3\",\n \"paths\": {\n \"/api/sample/users\": {\n \"get\": {\n \"operationId\": \"getUsersSample\",\n \"responses\": {\n \"200\": {\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"items\": {\n \"properties\": {\n \"name\": {\n \"type\": \"string\"\n }\n },\n \"type\": \"object\"\n },\n \"type\": \"array\"\n }\n }\n },\n \"description\": \"fetched users\"\n }\n },\n \"summary\": \"Get users\",\n \"tags\": [\n \"users\"\n ]\n }\n }\n },\n \"security\": [\n {\n \"bearerAuth\": []\n }\n ],\n \"servers\": [\n {\n \"url\": \"https://localhost:8080\"\n }\n ],\n \"x-tyk-api-gateway\": {\n \"info\": {\n \"name\": \"user\",\n \"state\": {\n \"active\": true\n }\n },\n \"server\": {\n \"listenPath\": {\n \"strip\": true,\n \"value\": \"/user-test-six/\"\n }\n },\n \"upstream\": {\n \"url\": \"https://localhost:8080\"\n }\n },\n \"x-tyk-streaming\": {\n \"streams\": {\n \"stream1\": {\n \"input\": {\n \"kafka\": {\n \"addresses\": [\n \"localhost:9093\"\n ],\n \"auto_replay_nacks\": true,\n \"checkpoint_limit\": 1024,\n \"consumer_group\": \"group1\",\n \"target_version\": \"3.3.0\",\n \"topics\": [\n \"instrument.json.AMZN\",\n \"instrument.json.GOOG\"\n ]\n }\n },\n \"output\": {\n \"broker\": {\n \"outputs\": [\n {\n \"stdout\": {\n \"codec\": \"lines\"\n }\n },\n {\n \"http_server\": {\n \"allowed_verbs\": [\n \"GET\"\n ],\n \"path\": \"/one\",\n \"stream_path\": \"/sse\",\n \"ws_path\": \"/ws\"\n }\n }\n ],\n \"pattern\": \"fan_out\"\n }\n }\n }\n }\n }\n}",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: <content-type>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{tenant}/api/apis/streams"
payload := strings.NewReader("{\n \"components\": {\n \"securitySchemes\": {\n \"bearerAuth\": {\n \"description\": \"The API Access Credentials\",\n \"scheme\": \"bearer\",\n \"type\": \"http\"\n }\n }\n },\n \"info\": {\n \"description\": \"This is a sample Streams API.\",\n \"title\": \"Streams Sample\",\n \"version\": \"1.0.0\"\n },\n \"openapi\": \"3.0.3\",\n \"paths\": {\n \"/api/sample/users\": {\n \"get\": {\n \"operationId\": \"getUsersSample\",\n \"responses\": {\n \"200\": {\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"items\": {\n \"properties\": {\n \"name\": {\n \"type\": \"string\"\n }\n },\n \"type\": \"object\"\n },\n \"type\": \"array\"\n }\n }\n },\n \"description\": \"fetched users\"\n }\n },\n \"summary\": \"Get users\",\n \"tags\": [\n \"users\"\n ]\n }\n }\n },\n \"security\": [\n {\n \"bearerAuth\": []\n }\n ],\n \"servers\": [\n {\n \"url\": \"https://localhost:8080\"\n }\n ],\n \"x-tyk-api-gateway\": {\n \"info\": {\n \"name\": \"user\",\n \"state\": {\n \"active\": true\n }\n },\n \"server\": {\n \"listenPath\": {\n \"strip\": true,\n \"value\": \"/user-test-six/\"\n }\n },\n \"upstream\": {\n \"url\": \"https://localhost:8080\"\n }\n },\n \"x-tyk-streaming\": {\n \"streams\": {\n \"stream1\": {\n \"input\": {\n \"kafka\": {\n \"addresses\": [\n \"localhost:9093\"\n ],\n \"auto_replay_nacks\": true,\n \"checkpoint_limit\": 1024,\n \"consumer_group\": \"group1\",\n \"target_version\": \"3.3.0\",\n \"topics\": [\n \"instrument.json.AMZN\",\n \"instrument.json.GOOG\"\n ]\n }\n },\n \"output\": {\n \"broker\": {\n \"outputs\": [\n {\n \"stdout\": {\n \"codec\": \"lines\"\n }\n },\n {\n \"http_server\": {\n \"allowed_verbs\": [\n \"GET\"\n ],\n \"path\": \"/one\",\n \"stream_path\": \"/sse\",\n \"ws_path\": \"/ws\"\n }\n }\n ],\n \"pattern\": \"fan_out\"\n }\n }\n }\n }\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "<content-type>")
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://{tenant}/api/apis/streams")
.header("Content-Type", "<content-type>")
.header("Authorization", "Bearer <token>")
.body("{\n \"components\": {\n \"securitySchemes\": {\n \"bearerAuth\": {\n \"description\": \"The API Access Credentials\",\n \"scheme\": \"bearer\",\n \"type\": \"http\"\n }\n }\n },\n \"info\": {\n \"description\": \"This is a sample Streams API.\",\n \"title\": \"Streams Sample\",\n \"version\": \"1.0.0\"\n },\n \"openapi\": \"3.0.3\",\n \"paths\": {\n \"/api/sample/users\": {\n \"get\": {\n \"operationId\": \"getUsersSample\",\n \"responses\": {\n \"200\": {\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"items\": {\n \"properties\": {\n \"name\": {\n \"type\": \"string\"\n }\n },\n \"type\": \"object\"\n },\n \"type\": \"array\"\n }\n }\n },\n \"description\": \"fetched users\"\n }\n },\n \"summary\": \"Get users\",\n \"tags\": [\n \"users\"\n ]\n }\n }\n },\n \"security\": [\n {\n \"bearerAuth\": []\n }\n ],\n \"servers\": [\n {\n \"url\": \"https://localhost:8080\"\n }\n ],\n \"x-tyk-api-gateway\": {\n \"info\": {\n \"name\": \"user\",\n \"state\": {\n \"active\": true\n }\n },\n \"server\": {\n \"listenPath\": {\n \"strip\": true,\n \"value\": \"/user-test-six/\"\n }\n },\n \"upstream\": {\n \"url\": \"https://localhost:8080\"\n }\n },\n \"x-tyk-streaming\": {\n \"streams\": {\n \"stream1\": {\n \"input\": {\n \"kafka\": {\n \"addresses\": [\n \"localhost:9093\"\n ],\n \"auto_replay_nacks\": true,\n \"checkpoint_limit\": 1024,\n \"consumer_group\": \"group1\",\n \"target_version\": \"3.3.0\",\n \"topics\": [\n \"instrument.json.AMZN\",\n \"instrument.json.GOOG\"\n ]\n }\n },\n \"output\": {\n \"broker\": {\n \"outputs\": [\n {\n \"stdout\": {\n \"codec\": \"lines\"\n }\n },\n {\n \"http_server\": {\n \"allowed_verbs\": [\n \"GET\"\n ],\n \"path\": \"/one\",\n \"stream_path\": \"/sse\",\n \"ws_path\": \"/ws\"\n }\n }\n ],\n \"pattern\": \"fan_out\"\n }\n }\n }\n }\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{tenant}/api/apis/streams")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = '<content-type>'
request["Authorization"] = 'Bearer <token>'
request.body = "{\n \"components\": {\n \"securitySchemes\": {\n \"bearerAuth\": {\n \"description\": \"The API Access Credentials\",\n \"scheme\": \"bearer\",\n \"type\": \"http\"\n }\n }\n },\n \"info\": {\n \"description\": \"This is a sample Streams API.\",\n \"title\": \"Streams Sample\",\n \"version\": \"1.0.0\"\n },\n \"openapi\": \"3.0.3\",\n \"paths\": {\n \"/api/sample/users\": {\n \"get\": {\n \"operationId\": \"getUsersSample\",\n \"responses\": {\n \"200\": {\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"items\": {\n \"properties\": {\n \"name\": {\n \"type\": \"string\"\n }\n },\n \"type\": \"object\"\n },\n \"type\": \"array\"\n }\n }\n },\n \"description\": \"fetched users\"\n }\n },\n \"summary\": \"Get users\",\n \"tags\": [\n \"users\"\n ]\n }\n }\n },\n \"security\": [\n {\n \"bearerAuth\": []\n }\n ],\n \"servers\": [\n {\n \"url\": \"https://localhost:8080\"\n }\n ],\n \"x-tyk-api-gateway\": {\n \"info\": {\n \"name\": \"user\",\n \"state\": {\n \"active\": true\n }\n },\n \"server\": {\n \"listenPath\": {\n \"strip\": true,\n \"value\": \"/user-test-six/\"\n }\n },\n \"upstream\": {\n \"url\": \"https://localhost:8080\"\n }\n },\n \"x-tyk-streaming\": {\n \"streams\": {\n \"stream1\": {\n \"input\": {\n \"kafka\": {\n \"addresses\": [\n \"localhost:9093\"\n ],\n \"auto_replay_nacks\": true,\n \"checkpoint_limit\": 1024,\n \"consumer_group\": \"group1\",\n \"target_version\": \"3.3.0\",\n \"topics\": [\n \"instrument.json.AMZN\",\n \"instrument.json.GOOG\"\n ]\n }\n },\n \"output\": {\n \"broker\": {\n \"outputs\": [\n {\n \"stdout\": {\n \"codec\": \"lines\"\n }\n },\n {\n \"http_server\": {\n \"allowed_verbs\": [\n \"GET\"\n ],\n \"path\": \"/one\",\n \"stream_path\": \"/sse\",\n \"ws_path\": \"/ws\"\n }\n }\n ],\n \"pattern\": \"fan_out\"\n }\n }\n }\n }\n }\n}"
response = http.request(request)
puts response.read_body{
"ID": "4c1c0d8fc885401053ddac4e39ef676b",
"Message": "API created",
"Meta": "665597e0b646b300011acb69",
"Status": "OK"
}{
"Message": "Couldn't read body.",
"Meta": null,
"Status": "Error"
}{
"Message": "Not authorised",
"Meta": null,
"Status": "Error"
}{
"Message": "Your license does not support adding/ modifying streams API configuration.",
"Meta": null,
"Status": "Error"
}{
"Message": "Found API with the same ID.",
"Meta": null,
"Status": "Error"
}{
"Message": "Error while creating API.",
"Meta": null,
"Status": "Error"
}Streams APIs
Create Streams API.
Create a Streams API Definition in Tyk OAS API format.
Note that the response includes the newly created Tyk Streams API Definition containing the unique identifier for the API (ID). You can provide a value for ID in the request body, otherwise Tyk will automatically generate a value.
POST
/
api
/
apis
/
streams
Create Streams API.
curl --request POST \
--url https://{tenant}/api/apis/streams \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: <content-type>' \
--data '{
"components": {
"securitySchemes": {
"bearerAuth": {
"description": "The API Access Credentials",
"scheme": "bearer",
"type": "http"
}
}
},
"info": {
"description": "This is a sample Streams API.",
"title": "Streams Sample",
"version": "1.0.0"
},
"openapi": "3.0.3",
"paths": {
"/api/sample/users": {
"get": {
"operationId": "getUsersSample",
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"items": {
"properties": {
"name": {
"type": "string"
}
},
"type": "object"
},
"type": "array"
}
}
},
"description": "fetched users"
}
},
"summary": "Get users",
"tags": [
"users"
]
}
}
},
"security": [
{
"bearerAuth": []
}
],
"servers": [
{
"url": "https://localhost:8080"
}
],
"x-tyk-api-gateway": {
"info": {
"name": "user",
"state": {
"active": true
}
},
"server": {
"listenPath": {
"strip": true,
"value": "/user-test-six/"
}
},
"upstream": {
"url": "https://localhost:8080"
}
},
"x-tyk-streaming": {
"streams": {
"stream1": {
"input": {
"kafka": {
"addresses": [
"localhost:9093"
],
"auto_replay_nacks": true,
"checkpoint_limit": 1024,
"consumer_group": "group1",
"target_version": "3.3.0",
"topics": [
"instrument.json.AMZN",
"instrument.json.GOOG"
]
}
},
"output": {
"broker": {
"outputs": [
{
"stdout": {
"codec": "lines"
}
},
{
"http_server": {
"allowed_verbs": [
"GET"
],
"path": "/one",
"stream_path": "/sse",
"ws_path": "/ws"
}
}
],
"pattern": "fan_out"
}
}
}
}
}
}'import requests
url = "https://{tenant}/api/apis/streams"
payload = "{\n \"components\": {\n \"securitySchemes\": {\n \"bearerAuth\": {\n \"description\": \"The API Access Credentials\",\n \"scheme\": \"bearer\",\n \"type\": \"http\"\n }\n }\n },\n \"info\": {\n \"description\": \"This is a sample Streams API.\",\n \"title\": \"Streams Sample\",\n \"version\": \"1.0.0\"\n },\n \"openapi\": \"3.0.3\",\n \"paths\": {\n \"/api/sample/users\": {\n \"get\": {\n \"operationId\": \"getUsersSample\",\n \"responses\": {\n \"200\": {\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"items\": {\n \"properties\": {\n \"name\": {\n \"type\": \"string\"\n }\n },\n \"type\": \"object\"\n },\n \"type\": \"array\"\n }\n }\n },\n \"description\": \"fetched users\"\n }\n },\n \"summary\": \"Get users\",\n \"tags\": [\n \"users\"\n ]\n }\n }\n },\n \"security\": [\n {\n \"bearerAuth\": []\n }\n ],\n \"servers\": [\n {\n \"url\": \"https://localhost:8080\"\n }\n ],\n \"x-tyk-api-gateway\": {\n \"info\": {\n \"name\": \"user\",\n \"state\": {\n \"active\": true\n }\n },\n \"server\": {\n \"listenPath\": {\n \"strip\": true,\n \"value\": \"/user-test-six/\"\n }\n },\n \"upstream\": {\n \"url\": \"https://localhost:8080\"\n }\n },\n \"x-tyk-streaming\": {\n \"streams\": {\n \"stream1\": {\n \"input\": {\n \"kafka\": {\n \"addresses\": [\n \"localhost:9093\"\n ],\n \"auto_replay_nacks\": true,\n \"checkpoint_limit\": 1024,\n \"consumer_group\": \"group1\",\n \"target_version\": \"3.3.0\",\n \"topics\": [\n \"instrument.json.AMZN\",\n \"instrument.json.GOOG\"\n ]\n }\n },\n \"output\": {\n \"broker\": {\n \"outputs\": [\n {\n \"stdout\": {\n \"codec\": \"lines\"\n }\n },\n {\n \"http_server\": {\n \"allowed_verbs\": [\n \"GET\"\n ],\n \"path\": \"/one\",\n \"stream_path\": \"/sse\",\n \"ws_path\": \"/ws\"\n }\n }\n ],\n \"pattern\": \"fan_out\"\n }\n }\n }\n }\n }\n}"
headers = {
"Content-Type": "<content-type>",
"Authorization": "Bearer <token>"
}
response = requests.post(url, data=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': '<content-type>', Authorization: 'Bearer <token>'},
body: '{\n "components": {\n "securitySchemes": {\n "bearerAuth": {\n "description": "The API Access Credentials",\n "scheme": "bearer",\n "type": "http"\n }\n }\n },\n "info": {\n "description": "This is a sample Streams API.",\n "title": "Streams Sample",\n "version": "1.0.0"\n },\n "openapi": "3.0.3",\n "paths": {\n "/api/sample/users": {\n "get": {\n "operationId": "getUsersSample",\n "responses": {\n "200": {\n "content": {\n "application/json": {\n "schema": {\n "items": {\n "properties": {\n "name": {\n "type": "string"\n }\n },\n "type": "object"\n },\n "type": "array"\n }\n }\n },\n "description": "fetched users"\n }\n },\n "summary": "Get users",\n "tags": [\n "users"\n ]\n }\n }\n },\n "security": [\n {\n "bearerAuth": []\n }\n ],\n "servers": [\n {\n "url": "https://localhost:8080"\n }\n ],\n "x-tyk-api-gateway": {\n "info": {\n "name": "user",\n "state": {\n "active": true\n }\n },\n "server": {\n "listenPath": {\n "strip": true,\n "value": "/user-test-six/"\n }\n },\n "upstream": {\n "url": "https://localhost:8080"\n }\n },\n "x-tyk-streaming": {\n "streams": {\n "stream1": {\n "input": {\n "kafka": {\n "addresses": [\n "localhost:9093"\n ],\n "auto_replay_nacks": true,\n "checkpoint_limit": 1024,\n "consumer_group": "group1",\n "target_version": "3.3.0",\n "topics": [\n "instrument.json.AMZN",\n "instrument.json.GOOG"\n ]\n }\n },\n "output": {\n "broker": {\n "outputs": [\n {\n "stdout": {\n "codec": "lines"\n }\n },\n {\n "http_server": {\n "allowed_verbs": [\n "GET"\n ],\n "path": "/one",\n "stream_path": "/sse",\n "ws_path": "/ws"\n }\n }\n ],\n "pattern": "fan_out"\n }\n }\n }\n }\n }\n}'
};
fetch('https://{tenant}/api/apis/streams', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{tenant}/api/apis/streams",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{\n \"components\": {\n \"securitySchemes\": {\n \"bearerAuth\": {\n \"description\": \"The API Access Credentials\",\n \"scheme\": \"bearer\",\n \"type\": \"http\"\n }\n }\n },\n \"info\": {\n \"description\": \"This is a sample Streams API.\",\n \"title\": \"Streams Sample\",\n \"version\": \"1.0.0\"\n },\n \"openapi\": \"3.0.3\",\n \"paths\": {\n \"/api/sample/users\": {\n \"get\": {\n \"operationId\": \"getUsersSample\",\n \"responses\": {\n \"200\": {\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"items\": {\n \"properties\": {\n \"name\": {\n \"type\": \"string\"\n }\n },\n \"type\": \"object\"\n },\n \"type\": \"array\"\n }\n }\n },\n \"description\": \"fetched users\"\n }\n },\n \"summary\": \"Get users\",\n \"tags\": [\n \"users\"\n ]\n }\n }\n },\n \"security\": [\n {\n \"bearerAuth\": []\n }\n ],\n \"servers\": [\n {\n \"url\": \"https://localhost:8080\"\n }\n ],\n \"x-tyk-api-gateway\": {\n \"info\": {\n \"name\": \"user\",\n \"state\": {\n \"active\": true\n }\n },\n \"server\": {\n \"listenPath\": {\n \"strip\": true,\n \"value\": \"/user-test-six/\"\n }\n },\n \"upstream\": {\n \"url\": \"https://localhost:8080\"\n }\n },\n \"x-tyk-streaming\": {\n \"streams\": {\n \"stream1\": {\n \"input\": {\n \"kafka\": {\n \"addresses\": [\n \"localhost:9093\"\n ],\n \"auto_replay_nacks\": true,\n \"checkpoint_limit\": 1024,\n \"consumer_group\": \"group1\",\n \"target_version\": \"3.3.0\",\n \"topics\": [\n \"instrument.json.AMZN\",\n \"instrument.json.GOOG\"\n ]\n }\n },\n \"output\": {\n \"broker\": {\n \"outputs\": [\n {\n \"stdout\": {\n \"codec\": \"lines\"\n }\n },\n {\n \"http_server\": {\n \"allowed_verbs\": [\n \"GET\"\n ],\n \"path\": \"/one\",\n \"stream_path\": \"/sse\",\n \"ws_path\": \"/ws\"\n }\n }\n ],\n \"pattern\": \"fan_out\"\n }\n }\n }\n }\n }\n}",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: <content-type>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{tenant}/api/apis/streams"
payload := strings.NewReader("{\n \"components\": {\n \"securitySchemes\": {\n \"bearerAuth\": {\n \"description\": \"The API Access Credentials\",\n \"scheme\": \"bearer\",\n \"type\": \"http\"\n }\n }\n },\n \"info\": {\n \"description\": \"This is a sample Streams API.\",\n \"title\": \"Streams Sample\",\n \"version\": \"1.0.0\"\n },\n \"openapi\": \"3.0.3\",\n \"paths\": {\n \"/api/sample/users\": {\n \"get\": {\n \"operationId\": \"getUsersSample\",\n \"responses\": {\n \"200\": {\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"items\": {\n \"properties\": {\n \"name\": {\n \"type\": \"string\"\n }\n },\n \"type\": \"object\"\n },\n \"type\": \"array\"\n }\n }\n },\n \"description\": \"fetched users\"\n }\n },\n \"summary\": \"Get users\",\n \"tags\": [\n \"users\"\n ]\n }\n }\n },\n \"security\": [\n {\n \"bearerAuth\": []\n }\n ],\n \"servers\": [\n {\n \"url\": \"https://localhost:8080\"\n }\n ],\n \"x-tyk-api-gateway\": {\n \"info\": {\n \"name\": \"user\",\n \"state\": {\n \"active\": true\n }\n },\n \"server\": {\n \"listenPath\": {\n \"strip\": true,\n \"value\": \"/user-test-six/\"\n }\n },\n \"upstream\": {\n \"url\": \"https://localhost:8080\"\n }\n },\n \"x-tyk-streaming\": {\n \"streams\": {\n \"stream1\": {\n \"input\": {\n \"kafka\": {\n \"addresses\": [\n \"localhost:9093\"\n ],\n \"auto_replay_nacks\": true,\n \"checkpoint_limit\": 1024,\n \"consumer_group\": \"group1\",\n \"target_version\": \"3.3.0\",\n \"topics\": [\n \"instrument.json.AMZN\",\n \"instrument.json.GOOG\"\n ]\n }\n },\n \"output\": {\n \"broker\": {\n \"outputs\": [\n {\n \"stdout\": {\n \"codec\": \"lines\"\n }\n },\n {\n \"http_server\": {\n \"allowed_verbs\": [\n \"GET\"\n ],\n \"path\": \"/one\",\n \"stream_path\": \"/sse\",\n \"ws_path\": \"/ws\"\n }\n }\n ],\n \"pattern\": \"fan_out\"\n }\n }\n }\n }\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "<content-type>")
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://{tenant}/api/apis/streams")
.header("Content-Type", "<content-type>")
.header("Authorization", "Bearer <token>")
.body("{\n \"components\": {\n \"securitySchemes\": {\n \"bearerAuth\": {\n \"description\": \"The API Access Credentials\",\n \"scheme\": \"bearer\",\n \"type\": \"http\"\n }\n }\n },\n \"info\": {\n \"description\": \"This is a sample Streams API.\",\n \"title\": \"Streams Sample\",\n \"version\": \"1.0.0\"\n },\n \"openapi\": \"3.0.3\",\n \"paths\": {\n \"/api/sample/users\": {\n \"get\": {\n \"operationId\": \"getUsersSample\",\n \"responses\": {\n \"200\": {\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"items\": {\n \"properties\": {\n \"name\": {\n \"type\": \"string\"\n }\n },\n \"type\": \"object\"\n },\n \"type\": \"array\"\n }\n }\n },\n \"description\": \"fetched users\"\n }\n },\n \"summary\": \"Get users\",\n \"tags\": [\n \"users\"\n ]\n }\n }\n },\n \"security\": [\n {\n \"bearerAuth\": []\n }\n ],\n \"servers\": [\n {\n \"url\": \"https://localhost:8080\"\n }\n ],\n \"x-tyk-api-gateway\": {\n \"info\": {\n \"name\": \"user\",\n \"state\": {\n \"active\": true\n }\n },\n \"server\": {\n \"listenPath\": {\n \"strip\": true,\n \"value\": \"/user-test-six/\"\n }\n },\n \"upstream\": {\n \"url\": \"https://localhost:8080\"\n }\n },\n \"x-tyk-streaming\": {\n \"streams\": {\n \"stream1\": {\n \"input\": {\n \"kafka\": {\n \"addresses\": [\n \"localhost:9093\"\n ],\n \"auto_replay_nacks\": true,\n \"checkpoint_limit\": 1024,\n \"consumer_group\": \"group1\",\n \"target_version\": \"3.3.0\",\n \"topics\": [\n \"instrument.json.AMZN\",\n \"instrument.json.GOOG\"\n ]\n }\n },\n \"output\": {\n \"broker\": {\n \"outputs\": [\n {\n \"stdout\": {\n \"codec\": \"lines\"\n }\n },\n {\n \"http_server\": {\n \"allowed_verbs\": [\n \"GET\"\n ],\n \"path\": \"/one\",\n \"stream_path\": \"/sse\",\n \"ws_path\": \"/ws\"\n }\n }\n ],\n \"pattern\": \"fan_out\"\n }\n }\n }\n }\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{tenant}/api/apis/streams")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = '<content-type>'
request["Authorization"] = 'Bearer <token>'
request.body = "{\n \"components\": {\n \"securitySchemes\": {\n \"bearerAuth\": {\n \"description\": \"The API Access Credentials\",\n \"scheme\": \"bearer\",\n \"type\": \"http\"\n }\n }\n },\n \"info\": {\n \"description\": \"This is a sample Streams API.\",\n \"title\": \"Streams Sample\",\n \"version\": \"1.0.0\"\n },\n \"openapi\": \"3.0.3\",\n \"paths\": {\n \"/api/sample/users\": {\n \"get\": {\n \"operationId\": \"getUsersSample\",\n \"responses\": {\n \"200\": {\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"items\": {\n \"properties\": {\n \"name\": {\n \"type\": \"string\"\n }\n },\n \"type\": \"object\"\n },\n \"type\": \"array\"\n }\n }\n },\n \"description\": \"fetched users\"\n }\n },\n \"summary\": \"Get users\",\n \"tags\": [\n \"users\"\n ]\n }\n }\n },\n \"security\": [\n {\n \"bearerAuth\": []\n }\n ],\n \"servers\": [\n {\n \"url\": \"https://localhost:8080\"\n }\n ],\n \"x-tyk-api-gateway\": {\n \"info\": {\n \"name\": \"user\",\n \"state\": {\n \"active\": true\n }\n },\n \"server\": {\n \"listenPath\": {\n \"strip\": true,\n \"value\": \"/user-test-six/\"\n }\n },\n \"upstream\": {\n \"url\": \"https://localhost:8080\"\n }\n },\n \"x-tyk-streaming\": {\n \"streams\": {\n \"stream1\": {\n \"input\": {\n \"kafka\": {\n \"addresses\": [\n \"localhost:9093\"\n ],\n \"auto_replay_nacks\": true,\n \"checkpoint_limit\": 1024,\n \"consumer_group\": \"group1\",\n \"target_version\": \"3.3.0\",\n \"topics\": [\n \"instrument.json.AMZN\",\n \"instrument.json.GOOG\"\n ]\n }\n },\n \"output\": {\n \"broker\": {\n \"outputs\": [\n {\n \"stdout\": {\n \"codec\": \"lines\"\n }\n },\n {\n \"http_server\": {\n \"allowed_verbs\": [\n \"GET\"\n ],\n \"path\": \"/one\",\n \"stream_path\": \"/sse\",\n \"ws_path\": \"/ws\"\n }\n }\n ],\n \"pattern\": \"fan_out\"\n }\n }\n }\n }\n }\n}"
response = http.request(request)
puts response.read_body{
"ID": "4c1c0d8fc885401053ddac4e39ef676b",
"Message": "API created",
"Meta": "665597e0b646b300011acb69",
"Status": "OK"
}{
"Message": "Couldn't read body.",
"Meta": null,
"Status": "Error"
}{
"Message": "Not authorised",
"Meta": null,
"Status": "Error"
}{
"Message": "Your license does not support adding/ modifying streams API configuration.",
"Meta": null,
"Status": "Error"
}{
"Message": "Found API with the same ID.",
"Meta": null,
"Status": "Error"
}{
"Message": "Error while creating API.",
"Meta": null,
"Status": "Error"
}Authorizations
The Tyk Dashboard API Access Credentials
Headers
Content type for streams endpoints should be application/vnd.tyk.streams.oas
Available options:
application/vnd.tyk.streams.oas Body
application/vnd.tyk.streams.oas
The description of OpenAPI v3.0.x documents, as defined by https://spec.openapis.org/oas/v3.0.3
Pattern:
^3\.0\.\d(-.+)?$Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Was this page helpful?