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:

Fig. Serve Web API
Fig. Serve Web API

Server Side

On the server side, just use the Web API Capability, along with graph references (or embedded subgraphs) to define endpoint behaviors:

  1. Use Reference node to reference graphs;
  2. Use Create Web API Capability to create an API endpoint.
  3. Use Serve node to start the server.
Fig. Web API Capability on the Server Side
Fig. Web API Capability on the Server Side

Client Side

On the client side, we can use Send Requst with corresponding method type.

  1. Use Send Request with corresponding method type send request; Make sure the URL correspond to the endpoint url.
  2. For GET, we usually don't need a body.
  3. Use Preview node to see result on the canvas.
Fig. Client Side
Fig. Client Side

Complete Setup

For the referenced graphs:

  1. Use Inputs node to define two inputs: String Map and String;
  2. Use Outputs node to output a single EndpointResponse;
  3. Use Make Endpoint Response to convert string values to EndpointResponse object.

Below shows the complete setup. The top two windows are the subgraphs referenced as handlers.

Fig. Setup
Fig. Setup

After running the server Serve, we can view the result of Send Request on the client (lower right).

Fig. Execution
Fig. Execution

References