3 min • read

Code

Speed up your API development by converting your API specification into boilerplate code to help you get started. Blackbird currently creates Go projects using templates.

You can also test and debug your APIs against production-like traffic before you promote your code to production, allowing you to inspect and troubleshoot in real-time.

Note: You must install Docker to use code run and code debug commands with Blackbird. For more information, see Get Docker.

Generate code

Use a sample template to generate code

First, download the sample petstore.yaml file to use for testing.

When using the sample template for Go projects, the following prompts display:

  • ProjectName: Provide a name for the new Go project. This will also be the name for the cmd in the project.
  • GoModule: Provide a name for the new Go project's go.mod module. For more information, see Using Go Modules.
  • GoVersion: Provide the Go version for your project. This value will also be used in go.mod.
  • enable GitHub Actions - Test module?: Generate a .github/build.yaml, configuring CI testing for the project using GitHub Actions.
  • enable Readme module? [y/n]: Generate a basic README.md file for the project.
  • enable Dockerfile module? [y/n]: Generate a basic Dockerfile to use with blackbird code run, blackbird code debug, and blackbird deployment create.

Use a local template to generate code

To generate code using a locally available template, pass the path to the template as an argument.

Use an existing API in Blackbird to generate code

To generate code using an existing API in the Blackbird catalog, pass the name of the API as an argument. For information on creating a new API in the catalog, see API Design Generation with Blackbird.

Note: You must use a version of OpenAPI Specification (OAS) 3.0.

Generate code without a template

To generate structs based on the the OpenAPI description, pass the argument to use our go template. This template is publicly available in our Github Generators Repository.

Build and run a local container with a remote server

To start debugging an API or mock, pass in the instance name as well as the path to the dockerfile and context.

Build and debug a local container with a remote server

This command is similar to the run command, but it attaches a debugger to the container.

Secure a code instance

By default, the remote code instance server endpoints are available publicly. To secure these endpoints, you can use API keys. You can also create and set an API key on creation with the --apikey-header flag. The following templates show the valid ways to enable an API key for code instance servers.