

KostasR
Members-
Content Count
13 -
Joined
-
Last visited
Community Reputation
1 NeutralRecent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
-
I'm using Andrea Magni's MARS REST API, which is based on Indy and therefore likely uses TidHTTP. The Delphi code I published is the PUT method of the MARS REST API.I'm using Andrea Magni's MARS REST API, which is based on Indy and therefore likely uses TidHTTP. The Delphi code I published is the PUT method of the MARS REST API.
-
Sorry to ask again: Is there no solution here, or am I asking the wrong question? OnAfterExcute procedure (AErr: Exception) only returns the error message but not the response object like in the method OnExecute procedure (AResponse: TStream) Does anyone have any ideas?
-
How to use Swagger via MARS REST API?
KostasR replied to KostasR's topic in MARS-Curiosity REST Library
If I understand correctly, this isn't a question for the MARS API, but rather what is the definition in Swagger? I'll look into that. Thank you. -
How to use Swagger via MARS REST API?
KostasR replied to KostasR's topic in MARS-Curiosity REST Library
I've looked at Demo OpenAPI. MARS builds a Swagger website with my resources. I have a POST method with a body param, containing the record. My question is now, how can I describe the fields of the record for swagger, i. e. the length of a string or the date format or if the field is required? Maybe with attributes? Is there any documentation? -
Is there documentation on how to use Swagger with the MARS REST API? For example, how can describe the body params in a POST method, such as string length, date format, required, etc.
-
rsUpdateLicence.PUT( procedure (AContent: TMemoryStream) var LJSONObject: TJSONObject; BirthDateStr, FormattedDate: string; begin JSONValueToStream(LJSONObject, AContent); end, procedure (AResponse: TStream) var LResponse: TJSONObject; begin LResponse := StreamToJSONValue(AResponse) as TJSONObject; try if Assigned(LResponse) then begin begin LicenseRespose := LResponse.ToRecord<TLicenseRespose>(); oResult := WriteData(LicenseRespose); end; finally LResponse.Free; end; end, procedure (AErr: Exception) begin ShowMessage('Error: ' + AErr.Message); // How can I get this error-object? end); How can I receive this error-object for error-handling in this method, see PostMan Image?
-
Log an error: [api] No implementation found for http method GET
KostasR posted a topic in MARS-Curiosity REST Library
It happens that a method is called that does not exist. Then I get the error message "[api] No implementation found for http method GET". Is there a way to write the called method and this parameters to a log? Regards Kostas -
Hell Andrea, I once had an inquiry regarding MARS. It was about being able to globally deactivate the roles of the methods for debugging purposes. I can then call and test the method via the web browser without a token. You said you would think about whether that is feasible. In the meantime, I'm supposed to do that via compiler switches. Have you already implemented this or is it too difficult? regards, Kostas
-
Hello all, I would like to send FormData to a third-party server and get a response as a JSON. Is that possible with the MARS client? If so, does anyone have a little example? I tested the communication via Postman. For this I sent a POST to the url. In the body, I set the form-data value pairs. Then I got the correct JSON. regards, Kostas
-
Hi, Do you mean the MARS\Demo\HelloWorld project? If so, I just compiled it on Delphi 10.4.1. It runs without any problems. If you mean the example MARS\Demos\MARSWebServer, I always use the template from MARS\Demos\MARSTemplate for new projects. Here the resource is registered without the anonymous method. The resource is created implicitly. initialization TMARSResourceRegistry.Instance.RegisterResource<THelloWorldResource>; // TMARSResourceRegistry.Instance.RegisterResource<THelloWorldResource>( // function: TObject // begin // Result := THelloWorldResource.Create; // end // ); There is another difference with Server.Forms.Main.pas FormCreate uses Web.HttpApp , MARS.Core.URL , MARS.Core.MessageBodyWriter, MARS.Core.MessageBodyWriters , MARS.Core.MessageBodyReader, MARS.Core.MessageBodyReaders , MARS.Utils.Parameters.IniFile, MARS.Core.RequestAndResponse.Interfaces ; --- procedure TMainForm.FormCreate(Sender: TObject); begin // MARS-Curiosity Engine FEngine := TMARSEngine.Create; try FEngine.Parameters.LoadFromIniFile; FEngine.AddApplication('DefaultApp', '/default', ['Server.*']); PortNumberEdit.Text := FEngine.Port.ToString; FEngine.BeforeHandleRequest := function (const AEngine: TMARSEngine; const AURL: TMARSURL; const ARequest: IMARSRequest; const AResponse: IMARSResponse; var Handled: Boolean ): Boolean begin Result := True; // skip favicon requests (browser) if SameText(AURL.Document, 'favicon.ico') then begin Result := False; Handled := True; end; // Handle CORS and PreFlight if SameText(ARequest.Method, 'OPTIONS') then begin Handled := True; Result := False; end; end; StartServerAction.Execute; except FreeAndNil(FEngine); raise; end; end; With these two changes I was able to compile and run the MARSWebServer project. http://localhost:8080/rest/default/helloworld In the resource, the path is set to c:\temp. Thus index.html is searched here. Regards, Kostas
-
Hello All, I would like to log errors. The TMARSActivation.RegisterInvokeError method in Server.Ignition seems to be suitable for this. It is called in the event of an error. But "AActivation.Method" is not assigned, so nothing is logged. Does anyone have any idea how AActivation.Method can be assigned? TMARSActivation.RegisterInvokeError( procedure (const AActivation: IMARSActivation; const AException: Exception; var AHandled: Boolean) var LErrorObj: TJSONObject; begin if Assigned(AActivation.Method) then ^^^^^^^^^^^^^^^^^^ begin LErrorObj := TJSONObject.Create; try LErrorObj.WriteStringValue('error', AException.Message); LErrorObj.WriteStringValue('resource', AActivation.Resource.Name); LErrorObj.WriteStringValue('method', AActivation.Method.Name); LErrorObj.AddPair('url', AActivation.URL.ToJSONObject); AActivation.Response.ContentType := 'application/json'; AActivation.Response.Content := LErrorObj.ToJSON; FThreadFileLog.Log(#13#10 + LErrorObj.ToString); AHandled := True; finally LErrorObj.Free; end; end; end ); Regards, Kostas
-
Hello All, I am currently trying to link MARS with an IO handler in order to be able to use HTTPS. Inspired by this post, stackoverflow indy-ssl-delphi-server This is what my code looks like. HTTPS is ignored. HTTP requests go through. Does anyone have MARS running with HTTPS? procedure TWEBService.ServiceCreate(Sender: TObject); var LScheduler: TIdSchedulerOfThreadPool; begin Name := TServerEngine.Default.Parameters.ByNameText('ServiceName', Name).AsString; DisplayName := TServerEngine.Default.Parameters.ByNameText('ServiceDisplayName', DisplayName).AsString; if WebRequestHandler <> nil then WebRequestHandler.WebModuleClass := WebModuleClass; FServer := TIdHTTPWebBrokerBridge.Create(nil); FIOHandler.SSLOptions.CertFile := 'certificate.crt'; FIOHandler.SSLOptions.KeyFile := 'private.key'; FIOHandler.SSLOptions.RootCertFile := 'SSLroot.crt'; FIOHandler.SSLOptions.Method := sslvSSLv23; FIOHandler.OnVerifyPeer := IOHandlerVerifyPeer; FServer.IOHandler := FIOHandler; FServer.OnQuerySSLPort := OnQuerySSLPort; try FServer.DefaultPort := TServerEngine.Default.Port; LScheduler := TIdSchedulerOfThreadPool.Create(FServer); try LScheduler.PoolSize := TServerEngine.Default.ThreadPoolSize; FServer.Scheduler := LScheduler; FServer.MaxConnections := LScheduler.PoolSize; FServer.OnParseAuthentication := ParseAuthenticationHandler; except FServer.Scheduler.Free; FServer.Scheduler := nil; raise; end; except FIOHandler.Free; FServer.Free; raise; end; end; Regards, Kostas