Standards, best practices and how-tos for developing OutSystems applications
🏗️ DRAFT This page is under construction
In this how-to we’ll create an ProductOrdering REST API for the Northwind database forge component using a design first approach.
The api must facilitate creating an order.
![Product Ordering Data Model][ProductOrderingDatamodel]
Derived from the Northwind Order data model we we need the following canonical structures:
Structure | Description |
---|---|
Category | Category canonical structure |
Customer | Customer canonical structure |
CustomersPage | List of customers and count |
Order | Order canonical structure |
OrderObject | Order and OrderProduct details |
OrderProduct | OrderProduct canonical structure |
OrdersPage | List of orders and count |
Product | Product canonical structure |
ProductObject | Product detailed structure |
ProductsPage | List of products and count |
Shipper | Shipper canonical structure |
To enable product ordering we require the following Api methods:
Name | HTTP Method | URL Path | Description |
---|---|---|---|
CategoryGet | GET | /categories | Returns a list of categories |
CustomerGet | GET | /customers | Retrieves a paginated list of customers |
CustomerGetById | GET | /customers/{customer_id} | Returns the customer details for a given customer. |
CustomerOrderGet | GET | /customers/{customer_id}/orders | Retrieves a list of orders for a specific customer. |
OrderCreate | POST | /orders | Place an order |
OrderGet | GET | /orders | Retrieve a paginates list of orders |
OrderGetById | GET | /orders/{order_id} | Return the details of a specific order |
ProductGet | GET | /products | Retrieve a paginated list of products that meet the search parameters. |
ProductGetById | GET | /products/{ProductId} | Retrieve details of a specific product. |
The product ordering api application consists of the following modules:
Because there is no naming convention for rest apis we adhere to the OutSystem [PascalCase] naming convention
For each method of the API we must provide a Canonical Business logic server action. This ensures that we don’t put business logic in the api implementation and have it available for reuse when exposing other protocols e.g. SOAP.
OFFSET @StartIndex ROWS FETCH NEXT @MaxRecords ROWS ONLY
ProductOrderingAPI
<Ctrl_3>
Integrations
Expose REST API
V1
and select Add REST API Method
Repeat this step for each of the following methods:
Name | Inputs | Output | Description | URL Path | Method |
---|---|---|---|---|---|
CustomerGetById | customer_id | customer | Returns the customer details for a given customer. | /customers/{customer_id} | GET |
CustomerCreate | customer | customer_id | Creates a new customer | /customers | POST |
CustomerDelete | customer_id | - | Deletes a specific customer | /customers/{customer_id} | DELETE |
CustomersGet | - | customers | Retrieves a list of customers | /customers | GET |
CustomerUpdate | customer | - | Updates a customer | /customers | PUT |
OrderCreate | order | order_id | Place an order | /orders | POST |
OrderGetById | order_id | order | Return the details of a specific order | /orders/{order_id} | GET |
OrdersGet | page, per_page | orders | Retrieve a paginated list of orders | /orders | GET |
CustomerOrdersGet | customer_id, status, page, per_page | orders | Retrieves a list of orders for a specific customer | /customers//customers/{customer_id}/orders | GET |
ProductsGet | category, search, per_page, page | products | Retrieve a paginated list of products that meet the search parameters. | /products | GET |
ProductGetById | product_id | product | Retrieve details of a specific product | /products/{product_id} | GET |
[[Wikipedia] Canonical schema pattern]: https://en.wikipedia.org/wiki/Canonical_schema_pattern [The Web API Checklist – 43 Things To Think About When Designing, Testing, and Releasing your API]: https://mathieu.fenniak.net/the-api-checklist/ [Schema-First API Design]: https://dzone.com/articles/schema-first-api-design [PascalCase]: https://www.theserverside.com/definition/Pascal-case [REST Customized Errors]: https://www.outsystems.com/forge/component-overview/15593/rest-customized-errors [how to Add Custom Authentication to an Exposed REST API]: /how-to/how-to-add-custom-authentication-to-an-exposed-rest-api.md [Appropriate record counting]: https://success.outsystems.com/documentation/11/managing_the_applications_lifecycle/manage_technical_debt/code_analysis_patterns/appropriate_record_counting/ [REST API Design Guidance]: https://microsoft.github.io/code-with-engineering-playbook/design/design-patterns/rest-api-design-guidance/ [Api stylebook - design guidelines]: http://apistylebook.com/design/guidelines/ [NLGov API Design Rules]: https://gitdocumentatie.logius.nl/publicatie/api/adr/ [OpenAPI Specification]: ttps://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md [ProductOrderingDatamodel]: /how-to/images/ProductOrderingDatamodel.png