smithy-go
smithy-go copied to clipboard
Examples of generated API client usage?
Do there exist any examples of generated API client code usage? I've been able to generate an API client for some Grafana endpoints, but can't yet figure out how to e.g. configure the API server address.
The Smithy code-generator currently doesn't have an opinionated structure on how endpoints are set or determined for a client. So the base generated client does not generate or register middleware that sets the endpoint. We have a pair GoIntegration
plugin on the the SDK side that has an opinionated approach to endpoints (EndpointResolver
type that takes a name of a region and returns an SDK specific endpoint structure describing a resolved endpoint). We then have our generated code based on the service's endpoints description and create a resolver and middleware that queries the endpoint and sets the endpoint for the underlying transport.
See AwsEndpointGenerator and EndpointGenerator for more in depth detail on how we are doing the code generation. ResolveEndpoint is an example of the generated middleware for the service client.
For the SDK's use case we needed to have a per client endpoint resolver and middleware due to our push to move away from a giant endpoints structure, and instead ship endpoints alongside the clients themselves. Depending on your use case you likely don't need this level of complexity.
I would note that smithy-go now supports modeled endpoint resolution, though the feature isn't part of the public IDL docs. That aside I have #458 open to track making smithy-go usable on its own, as of this writing it heavily depends on additional codegen support added in the v2 SDK to produce a working client.