Service Operations Tutorial - not working for me

In the demos folder there isn't the complete code of the example given in the tutorial.

By I type it in and recreate it manually.  First using the POST command.

I use the Delphi REST debugger to send:

POST   http://localhost:2002/nethd/myservice/sum?a=5&b=8 HTTP/1.1

With custom body of:

POST /nethd/myService/Sum HTTP/1.1
Host: localhost:2002
 
{
  "a": 5,
  "b": 8
}
 
I get the following:

500 internal server error

{
  "error":
  {
    "code":"TJsonReader.EObjectOrArrayExpected",
    "message":"Object or array expected as top-level value"
  }
}
So I try it using a GET instead and adding in the [HTTPGet] lines.

type
  [ServiceImplementation]
  TMyService = class(TInterfacedObject, IMyService)
  private
[HttpGet]
    function Sum(A, B: double): double;
//    function FindOverduePayments(CustomerId: integer): TList<TPayment>;
  end;

implementation

[HttpGet]
function TMyService.Sum(A, B: double): double;
begin
  Result := A + B;
end;

get http://localhost:2002/nethd/myservice/sum?a=5&b=8 HTTP/1.1

405 Method not allowed.

I wish the demos included the working source code of the tutorial.


After some trial and error I find that the custom body in the debugger does not need to have the first 2 lines. i.e. no POST and no Host.


POST /nethd/myService/Sum HTTP/1.1   - take this line out
Host: localhost:2002                                  - take this line out
 
{
  "a": 5,
  "b": 8
}

Hi Alan, yes, the text in documentation refers to the raw HTTP request, so the first lines are the request and headers themselves, and then after a line break you have the body of the request. You need to interpret it as it really depends on what client tool/rest debugger you are using to perform the request to the server.

OK, thanks.