unit CustomerService;

interface

uses
  Generics.Collections,
  XData.Service.Common;

type
  TCustomer = class
    Id: Integer;
    Name: string;
    Country: string;
  public
    destructor Destroy; override;
  end;

  {
    This service contract creates the following endpoints:
      GET /customers              -- Get all customers
      POST /customers             -- Create a customer
      GET /customers/:id          -- Get a specific customer
      PUT /customers/:id          -- Update a customer
      DELETE /customers/:id       -- Delete a customer
  }
  [ServiceContract]
  [Route('customers')]
  ICustomerService = interface(IInvokable)
    ['{D2981778-B681-4D4B-B95E-9816B5C7F1D1}']
    [HttpPost, Route('')]
    procedure CreateCustomer(Customer: TCustomer);
    [HttpGet, Route('')]
    function GetCustomers: TList<TCustomer>;
    [HttpGet, Route('{Id}')]
    function GetCustomer(Id: Integer): TCustomer;
    [HttpPut, Route('{Id}')]
    procedure UpdateCustomer(Id: Integer; Customer: TCustomer);
    [HttpDelete, Route('{Id}')]
    procedure DeleteCustomer(Id: Integer);
  end;

implementation

{ TCustomer }

destructor TCustomer.Destroy;
begin
  inherited;
end;

initialization
  RegisterServiceType(TypeInfo(ICustomerService));

end.
