Exposing a REST API in OutSystems allows you to enable other systems to retrieve or manipulate information through your application. Here’s a step-by-step guide to creating and exposing a REST API in OutSystems.
Create the REST API Service
- Open the Logic Tab: Navigate to the Logic tab within your OutSystems environment and open the Integrations folder.
- Expose REST API: Right-click on the REST folder and select “Expose REST API…”.
- Set the API Name: Choose a name for your REST API. It’s recommended to name the API according to its version (e.g., v1 for version one), but you can also use a more descriptive name like “PhoneBook”.
Create the REST API Method
- Add REST API method: Right-click on your newly created REST API and select “Add REST API Method”.
- Name your method: Set a name for your REST API method, such as GetContacts, CreateContact, or UpdateContact.
- Set the HTTP method: Choose the appropriate HTTP verb (GET, POST, PUT, DELETE) based on the action your method performs:
- GET: For reading data.
- POST: For creating new data.
- PUT: For updating existing data.
- DELETE: For deleting data.
- Design the method: Create the logic for your method. For example:
- GetContacts: Retrieves a list of all contacts.
- CreateContact: Receives a contact record and returns the ID of the created contact.
- UpdateContact: Receives a contact record and returns the ID of the updated contact.
Accessing Your REST API Endpoints
After deploying your application, your REST API endpoints will be accessible. Examples of such endpoints include:
- GET https://<server>/PhoneAPI/rest/v1/GetContacts – Retrieves all contacts.
- GET https://<server>/PhoneAPI/rest/v1/GetContact – Retrieves a specific contact.
- POST https://<server>/PhoneAPI/rest/v1/CreateContact – Creates a new contact.
- PUT https://<server>/PhoneAPI/rest/v1/UpdateContact – Updates an existing contact.
- DELETE https://<server>/PhoneAPI/rest/v1/DeleteContact – Deletes a contact.
- GET https://<server>/PhoneAPI/rest/v1/GetContactAddresses – Retrieves all addresses of a contact.
Customising Endpoints
OutSystems defines default endpoints based on the HTTP method and the name of the REST API methods, but you have the flexibility to customise these endpoints according to your needs.
Testing Your REST API
You can test your REST API methods using various tools such as Curl or Postman, or by building an OutSystems application specifically for testing purposes.
For manipulation methods (POST or PUT) that require an input parameter as a record, ensure you add the Content-Type header to your request with the value application/json.
Exposing APIs with Hubway Connect
While OutSystems provides a robust way to expose REST APIs, Hubway Connect simplifies and accelerates this process even further. Hubway Connect is a no-code solution designed to allow non-developer users to create, configure, and manage OData connections (APIs) efficiently. Here’s how Hubway Connect enhances your API exposure process:
- No-Code API Creation: With Hubway Connect, creating APIs is as simple as a few clicks. You don’t need to write any code, making it accessible to business users and reducing the load on your development team.
- Rapid Deployment: APIs can be generated and deployed in minutes, providing real-time access to data stored in OutSystems and other databases.
- Enhanced Data Governance: Hubway Connect ensures that data governance and security protocols are adhered to without the need for extensive coding.
- Seamless Integration: Easily integrate data from different sources and leverage powerful analytics tools to make informed business decisions.
- Cost Efficiency: By reducing the need for extensive development resources, Hubway Connect helps lower the overall cost of API development.
Ready to streamline your API management and boost your OutSystems platform’s capabilities? Discover the power of Hubway Connect today – sign up for a free 15-day trial and experience the benefits of no-code, hassle-free API management.