I need to call a REST API which is inside a WireGuard VPN. The WireGuard VPN is client managed, so I can't modify it. I am just provided with a configuration file to access the VPN.
I require a code-only solution that can function with only the capability of sending UDP packets. My application cannot modify the network configuration of either my network, or the REST API server's network.
This code solution may use Go, Python or JavaScript, as our existing codebase already uses all of these languages.
If there is a sufficiently useful solution in Java or C#, we can add those languages to our build chain.
WireGuard is designed to be used as a network interface, not as an application programming interface. It does not have an API.
If you have routing conflicts between a WireGuard network and the other networks to which a client is connected, and the client is running Linux, you could use policy routing rules on the client to ensure that only the traffic of a specific application or user is routed to the client's WireGuard interface. Alternately, you could run your application in a separate network namespace on the client, and attach the WireGuard interface just to that namespace.
If you really want to send and receive WireGuard traffic without setting up a network interface, you could create a custom application with the wireguard-go client, and use Go's virtual network stack (from the gVisor project) to set up a virtual WireGuard interface that can be accessed only from within that application. The wireguard-go source code includes a neat example of doing this to GET an HTTP resource:
root/tun/netstack/examples/http_client.go
Whatever you do, you must supply each client with its own IP address within the WireGuard network, as well as its own key pair. If the WireGuard server on the REST API side of the connection receives a request from two different clients using the same IP address or key pair at approximately the same time (i.e., receives a request from one before it can send a response to the other), it will try to send both responses to the client from which it received the last request (and nothing to the other client).