BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Ngrok JavaScript and Python SDKs Aim to Turn Ingress into a High-Level Abstraction

Ngrok JavaScript and Python SDKs Aim to Turn Ingress into a High-Level Abstraction

Bookmarks

The new ngrok JavaScript and Python SDKs enable embedding secure ingress into apps with a single line of code. It includes out-of-the-box support for capabilities such as high performance, resilience, security and observability, allowing developers to focus on their functional requirements.

The new SDKs provide a native mechanism for apps to deliver their services or for APIs to publish their endpoints through ngrok's global network. This is in addition to the stand-alone ngrok service which can be used through the command line or as a Kubernetes Ingress Controller. The SDKs can be used for example to provide ingress to customer's developer environments, to APIs in customer networks, or to APIs on devices running on external networks.

Thanks to the ngrok SDKs, developers need not concern themselves with low-level, non-functional details such as network primitives, IPs, NATs, certificates, load balancers, or ports, says ngrok.

Declaring ingress, which encompasses non-functional capabilities such as high performance, resilience, security and observability needed for flawless delivery of their software, directly in the application itself, radically simplifies the development process.

According to ngrok, the SDKs allow developers to precisely define the expected behavior between their applications and the ingress layer. Furthermore, by decoupling application ingress from the hosting environment, the ngrok SDKs enable platform independence and portability.

The following snippet shows how you can distribute a "Hello World" app using ngrok-python by simply calling ngrok.forward() on the same port where the HTTPServer is listening:

from http.server import HTTPServer, BaseHTTPRequestHandler
import ngrok, os
import asyncio

class HelloHandler(BaseHTTPRequestHandler):
    def do_GET(self):
        body = bytes("Hello", "utf-8")
        self.protocol_version = "HTTP/1.1"
        self.send_response(200)
        self.send_header("Content-Length", len(body))
        self.end_headers()
        self.wfile.write(body)

server = HTTPServer(("localhost", 8080), HelloHandler)
listener = ngrok.forward("localhost:8080", authtoken_from_env=True)
server.serve_forever()

Calling ngrok.forward() creates a secure and persistent outbound TLS connection to ngrok’s ingress-as-a-service platform, similar to what the ngrok agent would do when used through the command line.

Ngrok says they validated the design of their SDKs by collecting feedback from several open-source Python and JavaScript communities, including Stable Diffusion Web UI, Text Generation Web UI, Twurple, and Solana Payments App.

About the Author

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT