Writing, debugging and deploying webservices
This guide teaches you how to use the server_http node to build a web service.
In this exercise, we will create a simple web service which streams data to the client. The projects main node is the server_http
node which listens for incoming HTTP requests. It accepts an authentication node and needs to be terminated by a response
node.
Begin by dragging the following nodes onto the workspace:
miranda.server_http
Allow all
miranda.http_response
Then create a new node by right clicking on the workspace and selecting Create Node
. This node will be used to generate the data that will be streamed to the client. Rename the new code and call it Hello, world
.
Connect them according to the image below:
Right click on the Hello, world
-node and commit the following code to the execute function:
Before you can run the program there are two things you need to do:
- You need to build a custom image.
- Switch the bind_http switch to on before starting the processor.
When this is done you can click run and the HTTP server will start listening on port 443 on the following address: https://<job id>.p.mainly.cloud
The <job id>
you find if you click the job indocator in the top right of the workspace screen:
Here we see that the ID is 01hwawbp7aam0cx8jcwzt38vtj and if we go to https://01hwawbp7aam0cx8jcwzt38vtj.p.mainly.cloud/docs we can verify that the service is running. Next we need to write the client code. For this we need Visual Studio code or similar and an installed python environment on our desktop.
This is the client code we’re going to use:
We call the function like this:
We should expect to see the following output: