DEV Community

Luke Hagar
Luke Hagar

Posted on • Updated on

Building a world-class suite of SDKs is easy with Speakeasy

I have been personally maintaining a Plex Open API Specification for the last 10 months to improve the API documentation (plexapi.dev) and tools (SDKs) available to the Plex developer community.

In my free time, I started to build an SDK manually for Plex, but that was far too much work for the free time I had available.

I trialed generating SDKs using the OpenAPI Generator package, which was largely unsatisfactory.

I then started my foray into the world of private SDK generation offerings, and I found Liblab. Liblab was working with a fantastic premise, but its execution was lacking in several ways, from generating broken tests, to not fully supporting the OpenAPI Specification.

Finally, I found Speakeasy.

Speakeasy has a gorgeous website, a phenomenal user experience, and a swath of supported languages and features from Typescript to Terraform.

I was able to generate a fully functional SDK in less than an hour of work, and the support from the team was fantastic. I even found issues in my API spec not previously noticed, and the team was very helpful in identifying and resolving an issue with a duplicate key in Plex's API response for an endpoint.

Since then, I have generated SDKs in Typescript, C#, Python, Go, Java, PHP, Ruby, Swift, and even a Terraform provider and a NextJS Docs site.

Let's look at an example of using the generated Typescript SDK.

import { PlexAPI } from "@lukehagar/plexjs";

async function run() {
    const sdk = new PlexAPI({
        accessToken: "<YOUR_API_KEY_HERE>",
    });

    const res = await sdk.server.getServerCapabilities();

    if (res?.statusCode !== 200) {
        throw new Error("Unexpected status code: " + res?.statusCode || "-");
    }

    // handle response
}

run();

Enter fullscreen mode Exit fullscreen mode

This is such a clean and simple way to interact with the Plex API, lets see how other languages look.

Here is GO:

package main

import(
    "github.com/LukeHagar/plexgo/models/components"
    "github.com/LukeHagar/plexgo"
    "github.com/LukeHagar/plexgo/models/operations"
    "context"
    "log"
    "net/http"
)

func main() {
    s := plexgo.New(
        plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
    )


    var count *float64 = 1262.49

    var onlyTransient *operations.OnlyTransient = operations.OnlyTransientOne

    ctx := context.Background()
    res, err := s.Hubs.GetGlobalHubs(ctx, count, onlyTransient)
    if err != nil {
        log.Fatal(err)
    }

    if res.StatusCode == http.StatusOK {
        // handle response
    }
}
Enter fullscreen mode Exit fullscreen mode

And here is Python:

from os import getenv
from pprint import pprint
from plexsdk import PlexSDK
sdk = PlexSDK()
sdk.set_api_key(getenv("PLEXSDK_API_KEY"))
results = sdk.server.get_server_capabilities()

pprint(vars(results))
Enter fullscreen mode Exit fullscreen mode

Oh, look more super clean implementations of the Plex API.

I would wholly encourage anyone looking to generate an SDK for their API to give Speakeasy a try. Their quality of service and support is second to none, and their product is fantastic.

I am floored by the quality of SDKs that Speakeasy generates, and I am excited to see what the future holds for the Speakeasy team.

References:

Plex OpenAPI Specification here

My current Docs site here

Generated SDKs for typescript and go

Top comments (0)