Empowering Rapyd Payments with OpenAPI
Tags: openapi, api, swagger, apigateway
Published: 2023-09-18 19:19:56

OpenAPI, formerly known as Swagger, is a specification for designing, documenting, and consuming RESTful APIs (Application Programming Interfaces). OpenAPI provides a standardized way to describe the structure, operations, and functionality of an API. OpenAPI allows developers to generate documentation, create client SDKs (Software Development Kits), and automate API-related tasks.

## Why OpenAPI Matters for Rapyd

What is it that makes OpenAPI a valuable tool for developers? Here are some reasons why we would use OpenAPI at Rapyd.

API Documentation: OpenAPI allows us to generate interactive and user-friendly documentation for our API. It provides a machine-readable format that can be easily consumed by developers, making it easier for them to understand how to use our API effectively.

Design-First Approach: OpenAPI promotes a design-first approach to building APIs. By defining the API specification upfront, we can ensure consistency and clarity in the API's structure and behavior. This helps both the Product managers and Engineers to build the API, and the developer community to have a clear understanding of the API contract. You can think of an API contract as a recipe that tells two pieces of software how to talk to each other. Just as a cookbook that gives specific instructions on ingredients, and cooking steps the API contract will set rules on defining endpoints, data formats, and behavior to ensure seamless integration and interoperability.

Code Generation: OpenAPI specifications can be used to automatically generate client SDKs, server stubs, and other code artifacts. This saves time and effort by eliminating the need to write boilerplate code for API integration. Generated SDKs can provide a convenient way for developers to interact with our API using their preferred programming language.

Testing and Validation: OpenAPI specifications can be used to validate API requests and responses. We perform automated testing against the specification to ensure the API implementation adheres to the defined contract. This helps identify potential issues and inconsistencies early in the development process.

API Governance and Collaboration: OpenAPI provides a common language and format for describing APIs, making it easier for teams to collaborate on API design and development. It allows for better communication between API providers and consumers, enabling teams to work together effectively.

## Empowering API Developers

Once we publish an OpenAPI specification, consumers can use it to understand and interact with our API. 

Here's how consumers can leverage the OpenAPI specification:

Manual Integration: Developers can manually integrate with our API by referring to the OpenAPI specification. They can use the specification to understand the structure of the API's endpoints, the expected request payloads, and the format of the responses. By following the API contract defined in the OpenAPI specification, consumers can manually write code to make HTTP requests and handle the API responses in their preferred programming language.

Code Generation: OpenAPI allows for automatic code generation, which simplifies API integration for consumers. The OpenAPI specification can be used with code generation tools, such as Swagger Codegen or OpenAPI Generator, to generate client SDKs or libraries in various programming languages. These generated SDKs provide pre-built functions and classes that abstract away the low-level details of making API requests and handling responses. Consumers can then import these SDKs into their projects and use the provided methods and classes to interact with our API more easily.

API Explorers: Many API development platforms and tools provide built-in API explorers that can consume the OpenAPI specification and provide an interactive interface for testing and exploring the API. These explorers allow consumers to make API requests, view responses, and experiment with different parameters. Swagger UI and ReDoc are popular examples of API explorers that can consume OpenAPI specifications.

API Gateway Configuration: API management servers typically include an API gateway component that handles the routing and forwarding of API requests. By importing the OpenAPI specification into the API management server, the gateway can automatically configure the necessary routing rules based on the defined endpoints and paths in the specification. This simplifies the setup process and ensures that incoming requests are properly routed to the corresponding backend services.

Examples for use OpenAPI in API Management Gateways: 
https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-import-api.html 
https://learn.microsoft.com/en-us/azure/api-management/import-api-from-oas?tabs=portal 

## Getting started with Rapyd OpenAPI on Postman

1. Go to https://postman.com/rapyd-dev and goto Collections > Select Fork. 
2. Go to Environments, select the three dots next to RapydSB openAPI > Select Fork. 

As you fork both the Collection and Environment, you can import them into your own designated environment. 

1. Sign-up to [Rapyd Client Portal](https://dashboard.rapyd.net/sign-up), 
2. [Grab your API credentials](https://docs.rapyd.net/en/developers.html) to copy the access and secret keys from the Developers tab. 
3. Paste the access and secret key into the [Postman Environment](https://community.rapyd.net/t/set-your-api-keys-in-postman-rapyd-sandbox-environment/1055). 
5. Test your collection by calling GET https://sandboxapi.rapyd.net/v1/data/countries.

Note: The endpoint in Postman should look like `{{baseUrl}}/v1/data/countries`. 

## Copy the OpenAPI into Swagger 

1. Go to the [API section](https://www.postman.com/rapyd-dev/workspace/rapyd-dev/overview) in Rapyd OpenAPI in Postman. 
2. Select the down arrow on Rapyd-api
3. Select the down arrow on Definition. 
4. Select Rapyd-api-Beta.yaml or Rapyd-api.yaml. 
5. On the right panel, select the copy icon in between the wrap text and search icon. 

![Rapyd-OpenAPI-Postman-Copy-Definition](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qzg930co2y08u4haa3ra.png)

6. Go to the [Swagger Editor](https://swagger.io/tools/swagger-editor/) and paste the OpenAPI in the content section. 

Now you can look at generating samples and working on the Rapyd API right within Swagger. 


![Rapyd-OpenAPI-Swagger-Editor](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/boxlvepvf15f4b9wf4gj.jpg)

For any questions you can open up a topic in the [Rapyd Developer Community](https://community.rapyd.net/).