A client application will have a set of functions available to communicate data back and forth with a server. These functions might be triggered by some user action, or they might be automated to perform actions in the background. They might be chained together into a series of API requests to perform a more complex action. In general, each API function must perform the following steps:
Determine an HTTP Method and URL for the desired server endpoint.
Construct a list of query parameters, or construct a JSON object to be the body.
If required, add an Authorization token header to the request.
Send the HTTP request, wait for a response.
When the response arrives, check the HTTP Status for error codes.
If there are no errors, convert the JSON response object into a language specific data structure.
Alternatively, SwaggerHub has a built in tool called swagger-code-gen. This tool allows you to generate a client library for a variety of languages, and download it directly from the SwaggerHub documentation page. On any BrAPI SwaggerHub Page, click the “Export” menu in the top right corner, hover over “Client SDK”, then select from the list of languages/frameworks.
Note on generated code. Swagger-code-gen is a useful tool for converting API specs into code, but it is not perfect. Generated libraries will not be perfect, so be sure to review and test them before using in production.
The BrAPI Test Server is the primary resource for testing new BrAPI compatible client applications. The BrAPI Test Server has a complete implementation of every BrAPI endpoint with every version of the specification. It does not require authorization, but has a simple authorization system available for testing if needed. There is a Docker image available on DockerHub, so a development team could run the server independently for CI/CD testing.
All the data in the BrAPI Test Server is fake, and in some cases, unrealistic. If you are looking to test against realistic data, there are several server implementations within the BrAPI community with real data. Contact the BrAPI Slack channel to connect with another group in the community with the data you are looking for.
The brapi-intro-class github is a repository with example BrAPI implementations. All implementations follow the same use case where a user is browsing through Programs, Trials, and Studies. The code for getting Programs is included, but the critical code for Trials and Studies is missing. Choose a programming language you are most familiar with, and then fill in the missing code to complete the use case.