Redis API
#
DescriptionCreate an API to allow Redis to be accessible via REST calls.
Redis API is a simple service that allows applications to store and retrieve messages.
Several legacy applications
need a single location to store messages between stages, like a temporary cache. Redis API comes in handy when used as a messaging protocol between services using simple curl requests without a
massive Redis integration codebase.
#
UIAccess the DataTrucker URL via a browser
#
Create a credentials- Go to Credentials in the sidebar > Redis Credentials
- Scroll down to Credential Management
- Fill the form to create the connection
- Credential name โ an arbitrary value to identify the credential object
- The hostname of the Redis. Note, make sure the API server(not the UI) has access into Redis
- Port of the Redis Server
- Click on Create
#
Make an API#
Create a redis set API- Go to IOT API in the Sidebar > Redis SET APIs
- Fill the form to create the API
- Resource Name: an arbitrary name to identify the resource
- The Credential linked to the resources
- Method: The type of REST Call
- Source Type: Insert Data(SET) or Retrieve Data(GET)
- Validation Regex of Input values, input sanitization before querying
- Examples provided in the UI when you try to create a new API
#
Create a redis get API- Go to Database API in the Sidebar > Redis SET APIs
- Fill the form to create the API
- Resource Name: an arbitrary name to identify the resource
- The Credential linked to the resources
- Method: The type of REST Call
- Validation Regex of SQL Query, input sanitization before querying
- Examples provided in the UI when you try to create a new API. Documentation :
#
Query the resource you created################################ query a fetch endpoint#############################
URL: /api/v1/jobs/<resource name>TYPE: <method defined>HEADER: Authorization: "Bearer <JWT Token>"BODY (JSON): { "key": "<key>"}
Response: 200 OK{ jsondata....}
################################ query a set endpoint#############################URL: /api/v1/jobs/<resource name>TYPE: <method defined>HEADER: Authorization: "Bearer <JWT Token>"BODY (JSON): { "key": "<key>", "value": "<value>", "ttyl": <Integer, life(ttl) of the key-value pain in seconds" }
Response: 200 OK{ jsondata....}
#
As a CRD in Openshift / KubernetesFor credentials use the the API below to the management end point
---apiVersion: datatrucker.datatrucker.io/v1kind: DatatruckerFlowmetadata: name: datatruckerflow-samplespec: Resources: requests: memory: "256Mi" cpu: "250m" limits: memory: "256Mi" cpu: "500m" JobDefinitions: - resourcename: redis1 name: redis1 type: IOT-Redis credentialname: redis1 tenant: Admin restmethod: POST source_type: SET validations: type: object properties: key: type: string pattern: "^[a-zA-Z0-9_]*$" maxLength: 8 value: type: string pattern: "^[a-zA-Z0-9_]*$" maxLength: 8 ttyl: type: number Keys: configmap: placeholder Scripts: configmap: placeholder Type: Job DatatruckerConfig: datatruckerconfig-sample Replicas: 1 API: name: api Image: repository: docker.io imageName: datatruckerio/datatrucker-api tagName: latest
#
API#
Create a credential via RESTURL: /api/v1/credentials/TYPE: POSTHEADER: Authorization: "Bearer <JWT Token>"BODY (JSON): { "credentialname": "redisconnect", "type": "IOT-Redis", "hostname": "localhost", "port": 5433}
Response: 201 OK
#
Create the API via REST############################### create a Redis set-request #############################
URL: /api/v1/resourcesTYPE: POSTHEADER: Authorization: "Bearer <JWT Token>"BODY (JSON): { "resourcename": "redis1", "type": "IOT-Redis", "credentialname": "redis1", "restmethod": "POST", "source_type": "SET", "validations": { "type": "object", "properties": { "key": { "type": "string", "pattern": "^[a-zA-Z0-9_]*$", "maxLength": 8 }, "value": { "type": "string", "pattern": "^[a-zA-Z0-9_]*$", "maxLength": 8 }, "ttyl": { "type": "number" } } } }
Response: 201 OK
############################### create a Redis fetch request #############################
URL: /api/v1/resourcesTYPE: POSTHEADER: Authorization: "Bearer <JWT Token>"BODY (JSON): { "resourcename": "redis2", "type": "IOT-Redis", "credentialname": "redis1", "restmethod": "GET", "source_type": "GET", "validations": { "type": "object", "properties": { "key": { "type": "string", "pattern": "^[a-zA-Z0-9_]*$", "maxLength": 8 } } } }
Response: 201 OK