All docs
V21.2
21.2
21.1
The page you are viewing does not exist in version 21.1.
20.2
The page you are viewing does not exist in version 20.2.
20.1
The page you are viewing does not exist in version 20.1.
19.2
The page you are viewing does not exist in version 19.2.
19.1
The page you are viewing does not exist in version 19.1.
18.2
The page you are viewing does not exist in version 18.2.
18.1
The page you are viewing does not exist in version 18.1.
17.2
The page you are viewing does not exist in version 17.2.

Create Endpoints for Business Objects and Test the Web API (CTP)

  • 3 minutes to read

Important

We do not recommend that you use the Web API in production code. We made this service available to gather feedback from anyone who considers it for future use.

This topic describes how to create endpoints and test the Web API service. See the following topics for information on how to create a project with the Web API:

Create Endpoints

In the Startup.cs file, add or find the services.AddXafWebApi method call and use the BusinessObject method to create endpoints for business objects. The following code creates endpoints for the ApplicationUser and Contact business objects:

File: MySolution.WebApi\Startup.cs (MySolution.Blazor.Server\Startup.cs)

using MySolution.Module.BusinessObjects;
// ...
namespace MySolution.WebApi {
    public class Startup {
        // ...
        public void ConfigureServices(IServiceCollection services) {
            // ...
            services.AddXafWebApi(options => {
                options.BusinessObject<ApplicationUser>();
                options.BusinessObject<Contact>();
            });
            // ...
        }
        // ...    
    }
}

Use the Swagger UI to Test the Web API

If your solution includes a Web API project, right-click the project in the Solution Explorer and choose Debug | Start new instance to run the Web API project. A browser displays the page with the available endpoints.

If your solution includes a startup Blazor Server project that contains the Web API, run the application. Add /swagger to the application address (for example, https://localhost:44318/swagger ) and press Enter to display a page with available endpoints.

Refer to the following link for more information on the page’s UI: Swagger UI.

The default configuration starts the Web API service on different ports depending on the project:

Project

Default Port

Example

Web API project

44319

https://localhost:44319/swagger

Blazor Server project

44318

https://localhost:44318/swagger

XAF Web API

Test the Web API. Expand the GET ApplicationUser endpoint and click the Try it out button. The Execute button is displayed. Click this button to see the result.

Test the Web API Service

Use the Postman Tool to Test the Web API

You can also use the Postman tool to test the Web API. The Postman tool is more flexible and allows you to send complex requests with parameters to the Web API service. Refer to the following link for more information on how to utilize this tool: Sending your first request.

Tip

To test the Web API service hosted on localhost, install the Postman desktop agent as described in the following topic: Installing the Postman desktop agent.

The image below shows a request to the Contact business object filtered by FirstName in the Postman Web UI (https://web.postman.co/home):

Use Postman to create a Web API request

See the following topics for more information on OData query options:

If you enable authentication for your Web API service, specify the authorization settings for the Postman tool. See the following topic for details: Specifying authorization details. If the Web API service uses the XAF JWT token from the “Authenticate” endpoint, copy it from the Swagger UI page as described in the following section: Use the Swagger UI to Test the JWT Authentication.

See Also