1

Please help to understand about routing and web-url of web-service below.

type
  TAirportService = class(TInterfacedObject, IAirportService)
  public
    procedure GetAirportDefinition(const AirPortID: integer; out Definition: TDTOAirportDefinition);
  end;

procedure TAirportService.GetAirportDefinition(const AirPortID: integer;
  out Definition: TDTOAirportDefinition);
begin
  // create an object from static data
  // (real application may use database and complex code to retrieve the values)
  with Definition.Airport.Add do begin
    Location := 'LAX';
    Terminal := TRawUTF8DynArrayFrom(['terminalA', 'terminalB', 'terminalC']);
    Gate := TRawUTF8DynArrayFrom(['gate1', 'gate2', 'gate3', 'gate4', 'gate5']);
    BHS := 'Siemens';
    DCS := 'Altiea';
  end;
  with Definition.Airline.Add do begin
    CX := TRawUTF8DynArrayFrom(['B777', 'B737', 'A380', 'A320']);
    QR := TRawUTF8DynArrayFrom(['A319', 'A380', 'B787']);
    ET := '380';
    SQ := 'A320';
  end;
  Definition.GroundHandler := TRawUTF8DynArrayFrom(['Swissport','SATS','Wings','TollData']);
end;

procedure StartWebService();
var
  aModel: TSQLModel;
  aDB: TSQLRestServer;
  aServer: TSQLHttpServer;
begin
  // set the logs level to only important events (reduce .log size)
  TSQLLog.Family.Level := LOG_STACKTRACE+[sllInfo,sllServer];
  // initialize the ORM data model
  aModel := TSQLModel.Create([]);
  try
    // create a fast in-memory ORM server
    aDB := TSQLRestServerFullMemory.Create(aModel,'test.json',false,false);
    try
      // register our TAirportServer implementation
//      aDB.ServiceRegister(TServiceCalculator,[TypeInfo(ICalculatorXML)],sicShared);
      aDB.ServiceRegister(TAirportService,[TypeInfo(IAirportService)],sicShared);
      // launch the HTTP server
      aServer := TSQLHttpServer.Create('8092', [aDB], '+', useHttpApiRegisteringURI);
      try
        aServer.AccessControlAllowOrigin := '*'; // allow cross-site AJAX queries
        writeln('Background server is running'#10);
        write('Press [Enter] to close the server.');
        ConsoleWaitForEnterKey;
      finally
        aServer.Free;
      end;
    finally
      aDB.Free;
    end;
  finally
    aModel.Free;
  end;
end;

I try to call follow web-urls:

but every time I get:

{ "errorCode":400, "errorText":"Bad Request" }

or Bad request

Where am I wrong?

SpanishBoy
  • 1,797
  • 4
  • 21
  • 43
  • Isn't your job to set the servers ROOT redirects by calling `HTTPServer.RootRedirectToURI('api/default')` and `RESTServer.RootRedirectGet := 'api/default';`. I don't have direct experience with rest servers but I see others use such approach: http://stackoverflow.com/questions/32481966/delphi-whats-wrong-with-rest-api-based-on-mormot – SilverWarior Sep 11 '15 at 20:05
  • I example was used MVC, now I need only pure web-service... – SpanishBoy Sep 12 '15 at 00:32

1 Answers1

1

A was wrong, really urls below works as needed:

  • http://localhost:8092/root/AirportService/GetAirportDefinition?AirPortID=1
  • http://localhost:8092/root/AirportService.GetAirportDefinition?AirPortID=1
SpanishBoy
  • 1,797
  • 4
  • 21
  • 43