Generating Services when Consuming REST APIs in Martini
Martini enables developers to integrate RESTful web services by generating services tailored to their needs. You can choose to generate a service for every operation defined in an API by importing its full API schema, or create services for only the individual API operations you require. This document outlines four methods for consuming REST APIs, providing flexibility for various integration scenarios.
Methods to Consume REST APIs
1. Consuming an Entire API Specification
Downloading the API Specification from the Lonti Marketplace
- Access the Marketplace: Click on the Marketplace icon in the left navigation bar to explore available API specifications.
- Search the Marketplace: Enter a search term to find the required API.
- Review the Search Results: Select an API from the search results to view more details.
- Download the Specification: Click the Cog icon next to the required API and select "Install."
- Configuration: Choose the required API version and specify the Destination directory within a Package where you want the generated services to be created.
- Generate Services: Click "Install," and Martini will automatically generate a service for each operation defined in the specification.
Importing an API Schema
-
Navigate to the Consume API Interface: In Martini, open the Navigator view.
-
Start the Consume API Wizard: Right-click on your target package and select “New | Consume API” from the context menu to launch the Consume an API wizard.
-
Complete the Required Values:
-
Location: Browse to the directory within your package where you would like your generated services saved.
- Source: Select one of the following sources for your REST API schema:
- Swagger v2.0
- OpenAPI v3.0
- Postman Collection v2.1
- RAML
-
File/URL: Provide the file path or enter the URL for the API schema.
-
Optional Settings: To track events in the Tracker Transaction log, check "Log requests to Tracker." Note that logging to the Tracker may add overhead and consume additional database resources.
-
Complete the Import: Click “Consume” to generate services from the entire API specification. Martini will generate a service for each operation defined in the API specification, saving them to the specified directory.
2. Consuming a Single Operation from an API Specification
Using Martini’s HTTP Client and Exporting as a Service
-
Open the HTTP Client: In Martini Designer, access the HTTP Client via the left-hand navigation bar.
-
Configure the Request: Set up the HTTP method, URL, and any required headers or parameters for the specific operation.
-
Send and Test the Request: Send the request to verify the response and ensure it behaves as expected.
-
Export as a Service: Once verified, export the operation as a reusable service by selecting “Export as Service” in the HTTP Client. This will generate a service specifically for the single operation, ready for customization and use in workflows.
Creating an Ad Hoc Connection Using the Consume API Wizard UI
-
Navigate to the Consume API Interface: In Martini, open the Navigator view.
-
Start the Consume API Wizard: Right-click on your target package and select “New | Consume API” to open the wizard.
-
Complete the Required Values:
-
Location: Browse to the directory within your package where you would like your generated services saved.
- Source: Select “Adhoc REST/HTTP.”
-
Click Next.
-
Configure the Request: Enter the operation’s URL, HTTP method, Response Content Type (JSON or XML), and how to Return Content As (Object, String, InputStream, Byte Array).
-
Optional Settings: To automatically generate a reusable data model from the response, check "Generate Data Model from response."
-
Consume the Operation: Click “Consume” to generate a service based on the parameters provided. Repeat this process for each additional operation you wish to consume.
Configuring Authentication for Consumed REST APIs
For consumed REST APIs requiring authentication, Martini supports Basic Authentication and OAuth2. Authentication credentials can be configured using the Mapper for the Inputs of the Authentication service. The generated services will include input properties for these credentials, along with an authType
property to specify the authentication type. Ensure the necessary credentials are mapped for secure API interactions.
Reviewing and Customizing the Generated Services
After generating services, review them to ensure they meet your integration needs. Adjust input and output models, fine-tune the logic, and set up error handling to create a robust and reliable service.