Create Web API Server
Difficulty: ★★☆☆☆ (Intermediate) Rewards: ★★☆☆☆ (Medium) Context: Dataflow Context Read Time: 5 min
Web API server allows us to expose services on the internet through HTTP protocol.
Overview
Making web API server is quite easy once you understand the concepts. If you need a refresher, consult Knowledge Base on the topic.
We can make use of Ol'ista's Web API feature to develop simple web API servers in a graphical manner in the dataflow context:
Server Side
On the server side, just use the Web API Capability, along with graph references (or embedded subgraphs) to define endpoint behaviors:
- Use Reference node to reference graphs;
- Use Create Web API Capability to create an API endpoint.
- Use Serve node to start the server.
Client Side
On the client side, we can use Send Requst with corresponding method type.
- Use Send Request with corresponding method type send request; Make sure the URL correspond to the endpoint url.
- For GET, we usually don't need a body.
- Use Preview node to see result on the canvas.
Complete Setup
For the referenced graphs:
- Use Inputs node to define two inputs:
String MapandString; - Use Outputs node to output a single
EndpointResponse; - Use Make Endpoint Response to convert string values to
EndpointResponseobject.
Below shows the complete setup. The top two windows are the subgraphs referenced as handlers.
After running the server Serve, we can view the result of Send Request on the client (lower right).
References
- Knowledge Base on HTTP Methods
- Knowledge Base on REST API
- Framework reference for Ol'ista