Create Add REST API Endpoint
Before continuing, ensure your workstation has been set up with the Core Components, as well as components specific to the language ecosystem you're working in: [JavaScript] [Java] [.Net] [Python] [Rust]
This document provides a step-by-step guide to creating a new .NET REST API endpoint for our service using archetect. For this purpose, we use the Domain Gateway which exposes all the service APIs in the underlying domain. See Gateway Architectural Principles to understand how these components fit together.
Generating the Service
Using Archectect command below, generate the base web application
archetect render git@github.com:p6m-archetypes/dotnet-rest-domain-gateway.archetype.git
Archetect Prompts
When rendering the archetype, you'll be prompted for the following values:
Prompt | Description | Example | Required |
---|---|---|---|
Org Name | Organization this project belongs to | afi ,a1p ,... | Yes |
Solution Name | Project name | apps , booking-app ,... | Yes |
Project Prefix | Prefix for the Service Name | order , payment , booking | Yes |
For this tutorial, please use the below prompt values:
Prompt | Value |
---|---|
Org Name | a1p |
Solution Name | apps |
Project Prefix | Order |
Completing the above steps & providing prompts, should generate an order-service
in your working directory.
- order-service
-- OrderDomainGateway.Core
This module contains the main business logic file (e.g. OrderDomainGateway.Core.cs)
-- OrderDomainGateway.Server
This module contains the server runtime for the .NET service
-- OrderDomainGateway.IntegrationTests
This module contains all the unit and integration tests for the service
Running the service
Before running below please ensure grpc service packages have been published.
Once you have done the above, we need to add reference to the published Order Service Client in Order Domain Gateway.
Step 1 - Add Local NuGet repository
If you already have local NuGet repository source, you could skip this step
From the order-domain-gateway
root folder, run the below command:
dotnet nuget add source ~/.nuget_local --name LocalNuGet
Step 2 - Start the server
Please ensure you have Docker running on the machine
From the order-domain-gateway
root folder, run the below command:
dotnet run --project OrderDomainGateway.Server
Step 3 - Check the generated api docs
Test the server by opening the swagger url
Additional documentation
The generated service contains a README.md
in the root service folder. i.e. (order-domain-gateway/README.md
) Please go through this as well for additional information.