Table of Contents

Server method

What are server methods ?

Server methods are used to execute business code on the server-side. They can be exposed as an API.

Writing the code of a server method

In this article, we will focus on the available properties.

You can either write the C# code directly in the Neos Studio code editor or in Visual Studio (after the server method has been saved once). See more about adding/editing server code.

Method properties

  • Name : name of the server method, used to name the corresponding C# class and its interface.
  • Business assembly : business assembly that will contain the C# class representing the server method. The chosen assembly must belong to the server method module or one of its children.

Editing options :

  • Name : name of the server method, used to name the corresponding C# class and its interface.
  • Description : description of the server method

Advanced options :

  • Parameters and return type : lists the parameters that must be passed to the server method and its return type. Those informations are automatically deduced from the signature of the C# method in which your write the server method code. To add / update / delete a parameter or the return type, you just have to change the method signature. If the server method is exposed as an API, you can define how the parameters are passed to server method in the HTTP request.

API options :

  • Expose as API : Indicates whether the server method will be available via the API.
  • Authentication required [only if exposed as API] : Indicates whether the user must be authenticated and authorized to execute the server method. If set to false, anonymous connections are allowed.
  • Internal use only [only if exposed as API] : Indicates whether the access to the server method REST API endpoint is restricted to local incoming addresses. If set to true, requests from external servers will not be allowed.
  • Display in API explorer [only if exposed as API] : Indicates whether the method server REST API endpoind is displayed in the documentation UI (e.g. Swagger UI). If set to false, method server REST API endpoint is ignored by the API explorer.
  • HTTP method [only if exposed as API] : GET / POST / PUT / DELETE. When using the GET verb, the server method cannot persist data.
  • Route [only if exposed as API] : Determines the route to use to call the server method API.

Calling the server method from the client

The ServerMethods property is available on the client-side. It lists all the available server methods exposed in the API :

CopyOrderResult result = await ServerMethods.CopyOrder.ExecuteAsync(orderId);
await ShowMessageAsync(
    MessageType.Info,
    GroupeIsa.Northwind.Domain.Properties.Resources.Sales.OrderCopy,
    string.Format(GroupeIsa.Northwind.Domain.Properties.Resources.Sales.OrderCreated, result.OrderId));