Jump to content

Andrea Magni

Members
  • Content Count

    146
  • Joined

  • Last visited

  • Days Won

    3

Posts posted by Andrea Magni


  1. Hi, now I get what you meant, sorry.

    To design your API in OpenAPI 3 format (for example) and to have the corresponding API implemented in MARS.

    This is something I'd like to add as a feature but I would say not in the immediate future.

    I've added (in the past) OpenAPI3 support to MARS, meaning the library will emit an OpenAPI3 description of your API (the other way around with respect to what you are asking).

     

    It would be a nice addition to cover your use case.

     

    I'll let you know if I'll find time to implement it (of course I would appreciate contribution as MARS is an OS project so if you feel to contribute, you are welcome!).

     

    Sincerely,

    Andrea

     

    • Like 1

  2. Hi, you can start following instructions to install the library, if you haven't already. Check this link: https://github.com/andrea-magni/MARS/blob/master/docs/Installation.md

     

    After that, find, compile and run the MARSCmd utility ( Utils/Source/MARScmd folder in your repository clone).

    It will guide you through a simple wizard to startup your first MARS application, cloning the Demos/MARSTemplate project group.

     

    You should have your first MARS REST server application up and running in 1 minute.

     

    Sincerely,

    Andrea 


  3. Hi, yes you can easily read request's header:

    1) using the HeaderParam attribute to decorate a field of your resource (or an argument of your method) to retrieve the value

    2) accessing the IMARSActivation and the Request field to have a more direct access to the underlying request object

     

    Other thing is to use that header to provide authentication/authorization through MARS built-in facilities. We can explore that too, just let me know what you need and some examples of requests.

     

    Sincerely,

    Andrea


  4. Hello Ertan,

    you may want to check the AfterInvoke capabilities:

     - you can define a local method in your resource class that will be called after the request has been executed, yet before connection is closed; that seems a good place to cleanup temporary files

     - there is also a global mechanism ( look for  TMARSActivation.RegisterAfterInvoke in Server.Ignition.pas in the MARSTemplate Demos folder).

     

    Hope this helps, let me know if you need something more.

     

    Sincerely,

    Andrea


  5. Dear Kostas,

    firstly I want to apologize not being much available these months. I've been very busy and many things fell behind.

     

    The easiest way to log errors in MARS is to provide an InvokeError handler:

     

        TMARSActivation.RegisterInvokeError(
          procedure (const AActivation: IMARSActivation; const AException: Exception; var AHandled: Boolean)
          begin
            CodeSite.SendError('Error: ' + AException.Message + ' Path: ' + AActivation.URL.Path);
          end
        );

     

    There is an (empty) example of this in Server.Ignition.pas unit of the MARSTemplate (Demos folder).

     

    Hope this helps!

     

    Sincerely,

    Andrea

     


  6. Hi @John Kouraklis and @Remy Lebeau, thanks for this topic that helped me too.

    Just wanted to add I think we should free the enumerator object (returned by TDictionary<>.GetEnumerator).

    I've used this approach in MARS REST library, as you can see here:

    https://github.com/andrea-magni/MARS/blob/41fd78e5416e38fad0f6a0451402a10824aa62c4/Source/MARS.YAML.ReadersAndWriters.pas#L222

     

    Thanks again you both.

     

    Andrea

    • Like 1

  7. Hi @Galina, sorry for the late reply.

    MARS is pretty compatible with older Delphi version up to XE... This is true especially for the server side. The client side has some features relying on the Parallel Programming Library (thus XE7+) but should compile with older version too.

     

    Let me know if you encounter issue compiling with older Delphi versions, I will try to help.

     

    Sincerely,

    Andrea


  8. Hi @Stuart Clennett,

    sorry for the late reply! 

    TMARSClientToken component has the capabilities to persist the token (and the related informations) through Load/Save From/To File/Bytes routines.

    I am considering to introduce also a way to update the component setting a bare JWT token but this would require to compile the JWT library (mORMotJWT or JOSE) on the client side.

     

    Let me know your thoughts about it.

    Sincerely,

    Andrea


  9. Hi, nice question, sorry for the late of my reply.

     

    One thing you can do is to have an inheritance hierarchy. TResourceB may inherit from TResourceA.

    That way it should be easy to include data from GetSubData in the GetAllData result.

    You can still keep two distinct resources and MARS will inject everything on this or that class depending on the matching of the request path.

     

    Another way would be to pass the Context-Injected instance from one resource to the other. Through an overloaded method for example. Or through a property.

     

    I am going to make the injection mechanism more available to direct use in the future. Stay tuned. 

     

    Sincerely,

    Andrea


  10. Hi Kostas,

    the MARSWebServer demo has been created way before the InvokeError mechanism has been introduced.

    The resource takes care to send a 404 response when a URL is not matching a file system entry (no actual error is raised, a custom response is sent). This means it's unlikely you'll ever get to the InvokeError anonymous handler you registered. You have a chance to have it called if you are addressing a non existent resource (different from helloworld).

     

    If you will explain me your needs we may improve the demo or build a new one.

     

    Sincerely,

    Andrea


  11. Hi all, 

    I just wanted to let you know my (long-awaited) FMX book is now available (actually it is rolling out on Packt and Amazon so availability may be different across different countries).

    If you like to read some details you can read my latest blog post: https://blog.andreamagni.eu/2020/10/book-delphi-gui-programming-with-firemonkey-now-available/

     

    I really hope the book will be useful to spread Delphi and FMX as development platform.

     

    Thanks for the attention,

    Andrea

    • Like 12
    • Thanks 5

  12. Embarcadero just release Patch 2 for 10.4 Sydney (https://blog.marcocantu.com/blog/2020-july-radstudio104-patch2.html).

    Once applied, you won't be able to compile MARS master branch. There is an issue with record constraint on generic calls (https://quality.embarcadero.com/browse/RSP-30078).

    I've just pushed a (temporary) branch of MARS where all the record constraints have been removed (thus it compiles and it seems to work as expected for what I can say at the moment).

    You can find it here: https://github.com/andrea-magni/MARS/tree/104Patch2

     

    Sincerely,

    Andrea


  13. Hi @Alfredo I.,

    thanks for using MARS!

     

    Please have a look at the Authorization demo. Just compile and run the server and open a browser at http://localhost:8080/rest/default/token/html

     

    You should see a simple HTML page allowing you to login/logout. The mechanism is cookie-based and it really seems your same situation.

     

    Please let me know if you find out what's not working in your case.

     

    Sincerely,

    Andrea


  14. I've added a hack (accessing a protected field of TIdHTTPAppRequest casting a reference to TWebRequest to a subclass) that seems (and should reasonably) work.

    The hack only relates to those deployment methods where Indy is not letting me access the TWebRequestInfo data structure (Apache modules, IIS ISAPI, Windows Service).

    From now on, you can use the GetHeaderParamCount, GetHeaderParamValue, GetHeaderParamIndex methods of IMARSRequest interface.

     

    uses MARS.Core.RequestAndResponse.Interfaces;

     

    // in your resource definition or as a method argument

    [Context] FReq: IMARSRequest;

     

    Let me know if this is enough. Feel free to reopen issue #95 if needed.

     

    Sincerely,

    Andrea


  15. Hi @bioman,

    thanks for pointing out compilation broke. I just fixed it: https://github.com/andrea-magni/MARS/issues/94

     

    About the encoding, MARS is a layer of abstraction over the transport protocol (http). You implement your method (I guess) returning a Delphi string value.

    MARS serializes (where needed) the values to a stream that will be used as the response of the request. Then, it's the underlying http library (MARS supports Indy, WebBroker over Apache module and IIS ISAPI and, more recently, Delphi Cross Socket framework) that sends the content to the client.

    Indy has this trend of setting Content-Type=text/html; charset=ISO-8859-1 as default so sometimes you get it (when using Indy/WebBroker as http layer for MARS).

    MARS (and Indy neither) can't easily say if your string is a UTF8 or MBCS or ANSI string, but you should know for sure.

    So, if you are sending an UTF8 content in your string, mark your resource/method with an Encoding attribute stating so.

    [GET, Path('geoconding.html'), Encoding('UTF-8')]
    function MyContentGenerator: string;

     

    Let me know if you solve this way!

    Sincerely,

    Andrea

    • Haha 1
×