Skip to content
Snippets Groups Projects
Select Git revision
0 results

README.md

Blame
  • xxdk Restlike Connect Client Example

    This mini-repository contains the example logic for running a basic REST-like connection client. This is provided by the xx network team as a springboard to help consumers better understand our API and how it may be used.

    main.go contains the crux of the logic. We avoid complicating our example by avoiding the usage of CLI flags for basic variables you may change in the code. This file initiates an xxdk E2E object. With that client established, a REST-like client is built on top. Using a precanned contact object created in restConnectServer this REST-like client contacts the server with a simple request.

    utils.go contains utility functions for running the program. In this case, we provide a tool initializing a log.

    Build Instructions

    In these instructions we will go over building a REST-like client using our example. In order to build a client which successfully sends a request and receives a response, we must first go over how to build and run a REST-like connect server.

    Building a Server

    In order to run a server, the following commands may be run:

    cd restConnectServer/
    go build -o server .
    ./server 

    This will initialize the server. You may verify its functionality by checking the server.log file. It is a long-running process which may be stopped by a user inputted kill signal. This will create a file restConnectServer.xxc, which is the contact file for the server. A REST-like client may parse this file in order to send a request to this server.

    Building a Client

    Please follow the steps above before continuing to these instructions. In order to run the client, you must first move the aforementioned restConnectServer.xxc file to the path where you will run the client.

    cd restConnectServer/
    cp restConnectServer.xxc /path/to/restConnectClient

    Once the contact object is local to the client, you may build and run the client:

    cd restConnectClient/
    go build -o client .
    ./client 

    This is a long-running process which may be stopped by a user inputted kill signal. We recommend allowing the process to run for a long enough time to complete its requests to the server and receive the server's responses. We go into detail on what this entails below.

    Once the REST-like client has set up and sent its request, you can verify by checking the server's log for the string Request received:

    grep "Request received: " restConnectServer/server.log 
    INFO 2022/07/12 14:51:56.184948 Request received: headers:{headers:"This is a header"}  method:1  uri:"handleClient"
    INFO 2022/07/12 14:52:05.677718 Request received: headers:{headers:"This is a header"}  method:1  uri:"handleClient"

    By default, the client sends two requests, synchronous and asynchronous. Both requests should be received by the server in order to accomplish a successful client-server request.

    In order to verify the response, look at the client log for the string Response: :

    grep "Response: " restConnectClient/client.log
    INFO 2022/07/12 14:52:00.881453 Response: content:"This is content"  headers:{headers:"this is a response"}
    INFO 2022/07/12 14:52:09.540666 Response: content:"This is content"  headers:{headers:"this is a response"}

    As by default, there are two requests received by the server, the client will receive two responses.