Skip to main content

Create Add REST API Endpoint

info

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:

PromptDescriptionExampleRequired
Org NameOrganization this project belongs toafi,a1p,...Yes
Solution NameProject nameapps, booking-app,...Yes
Project PrefixPrefix for the Service Nameorder, payment, bookingYes

For this tutorial, please use the below prompt values:

PromptValue
Org Namea1p
Solution Nameapps
Project PrefixOrder

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

Service Client Packages

Before running below please ensure grpc service packages have been published.

See instructions here

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

Docker

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.