Jump to content

Andrea Magni

Members
  • Content Count

    146
  • Joined

  • Last visited

  • Days Won

    3

Posts posted by Andrea Magni


  1. Thanks, I am using a portion of mORMot (check my mORMotJWT repository: https://github.com/andrea-magni/mORMot-JWT) I have extracted (with permission) in order to benefit of their JWT implementation (that is way better than the JOSE implementation). Unfortunately, they are (were?) not supporting Linux compilation with Delphi because of ARC. That's the reason I still have JOSE and mORMotJWT support at the same time.

     

    Glad you solved!

     

    Sincerely,

    Andrea

    • Like 1

  2. Hi @Stuart Clennett,

    my fault! I forgot to update some prototypes here and there. Thanks for pointing this out:

     

    add these to the uses clause:

      , MARS.Core.URL, MARS.Core.RequestAndResponse.Interfaces

     

    change the BeforeHandleRequest assignment to :

     

        FEngine.BeforeHandleRequest :=
          function (const AEngine: TMARSEngine;
            const AURL: TMARSURL; const ARequest: IMARSRequest; const AResponse: IMARSResponse;
            var Handled: Boolean
          ): Boolean
          begin


    Thanks! I'll fixit in the repo ASAP

     

    Andrea

     

     

    • Like 1

  3. On 6/21/2020 at 11:50 PM, ertank said:

    You can use MARS with Community Edition.

    Some examples depend on some FireDAC units which belong to higher edition.

    Right, thanks @ertank!

    In the Source/MARS.inc file there is a specific define to state FireDAC support is included or not:

     

    https://github.com/andrea-magni/MARS/blob/edb3c7e7a43dbac2f94f124b08107a6c3f4b5074/Source/MARS.inc#L1

     

    Sincerely,

    Andrea


  4. Hi Marzio,

    TMARSResponse is intended to be used as return type of your REST methods.

    If you are looking for a reference to the response object (implemented by the http layer) the second writing is correct.

     

    Soon, I'll release a new MARS version and there will be an IMARSResponse interface, wrapping the underlying object (MARS will be soon able to abstract from the http layer, in order to allow use of DelphiCrossSockect along side of Indy and other libraries).

     

    Sincerely,

    Andrea


  5. Hi, sorry for the late, I am trying to catch up with all messages here and on github.com.

    I saw the issue (81) and yesterday I made some work on the develop branch (rebasing it onto master). I attached files with your corrections to the issue, please file a pull request and I will be happy to accept it (and you will show up as a contributor as well).

     

    Thanks


  6. 8 hours ago, stijnsanders said:

    Does MARS do streaming? Or does MARS do transfer-encoding chunked? (If so, you're apparently supposed to gzip first and then do the chunking...)

     

    Frank Lauter suggested me to implement chunking in MARS but I haven't done it yet.

    I guess one should implement some sort of caching in order to avoid continuously gzipping the same content just to serve a specific chunk to the client.

    Would be very interesting to cover this as it may result in a great performance boost for large data transfers.

     

    Sincerely,

    Andrea


  7. Hi @Bjørn Larsen,

    thanks for you contribution!

    Some thoughts:

    1. I would say compression should be done as last step before sending back the response to the client. I mean, we can take advantage of the AfterInvoke mechanism (attaching an handler or not according to Engine parameters). This should be more generally available to all MARS TMARSActivation implementation (only one in the official repository, I know). Another point is that some deployment methods (Apache/IIS) may provide compression natively and I would let this instead of our implementation.
      What about moving your implementation to the Server.Ignition unit (MARSTemplate demo)? See code below as draft... I guess one could even implement a symmetric BeforeInvoke to support compression also the other way around (from client to server), I don't know how this is popular/expected, however.
    2. Using Response.SetHeader may lead to multiple Content-Encoding headers to be set at the same time (TPrimitiveTypesWriter, in MARS.Core.MessageBodyWriters.pas for instance sets the Content-Encoding to provide some information about text encoding. This may be a mine misunderstanding however... I need to check this sooner or later... if anyone has something to say about this, please do!). I switched to setting the Response.ContentEncoding property as I was having trouble with Postman (and Chrome) when multiple Content-Encoding headers were set.

     

        // Compression
        if FEngine.Parameters.ByName('Compression.Enabled').AsBoolean then
          TMARSActivation.RegisterAfterInvoke(
            procedure (const AActivation: IMARSActivation)
            var
              LOutputStream: TBytesStream;
            begin
              if ContainsText(AActivation.Request.GetHeaderParamValue('Accept-Encoding'), 'gzip')  then
              begin
                LOutputStream := TBytesStream.Create(nil);
                try
                  ZipStream(AActivation.Response.ContentStream, LOutputStream, 15 + 16);
                  AActivation.Response.ContentStream.Free;
                  AActivation.Response.ContentStream := LOutputStream;
                  AActivation.Response.ContentEncoding := 'gzip';
                except
                  LOutputStream.Free;
                  raise;
                end;
              end;
            end
          );

     

    Let me know what you think about. I would be glad to accept your PR then...

     

    Sincerely,

    Andrea

     


  8. Hi @bioman, glad you sorted out in the meantime.

    The "FireDAC Basic" demo is the dataset-oriented (quite C/S+briefcase) way of handling data through MARS.

    I would suggest to have a look to EKON22 demo, specifically looking for the TRecord<R>.FromDataSet and the use of TMARSFireDAC there.

     

    Sincerely,

    Andrea  


  9. Hi @Yaron,

    I don't have actual numbers about the most reliable/best performance deployment method but my preferred deployment method for production is having an internal MARS REST server (Windows Service or Linux Deamon) and Apache acting as a reverse proxy (implementing SSL, caching, compression, eventually load balancing). This grants quite some granularity with respect to performance tuning and service availability (you can restart a single service or the whole thing).

    I also have deployed some MARS servers as Apache modules (on Linux).

     

    A couple of customers are using MARS with IIS: one is using IIRF (basically making IIS a reverse proxy and SSL implementor), keeping MARS servers standalone (not even Windows Services though this is on the roadmap). The other one is using ISAPI deployment.

    I have news from time to time from people using the library and there is not a clear trend among available deployment methods.

     

    Sincerely,

    Andrea

    • Like 1

  10. Hi @bioman,

    there are several approaches to the topic (CRUD operation against a DB). MARS doesn't dictate one specifically.

     

    Would you please specify if you are building a Delphi to Delphi solution (Delphi on the client and Delphi on the server)?

    You can have a dataset-oriented approach (client asks for a dataset, modifies it, changes are sent back to the server in form of delta updates) or a more general record-oriented approach (client asks for data, server sends a JSON array, client makes POST or PUT calls with modified/new data records).

    It also matters if you are looking for a data-centric approach (i.e. sending whole records from DB to client and back) or more interpolated approach (client commands REST server to perform operations that results in data manipulation).

     

    MARS is a lightweight library and I am trying not to dictate some aspects (more related to application than library IMO) so there are many ways to use it.

     

    Thanks for the kind words!

    Sincerely,

    Andrea

     

     


  11. On 7/30/2019 at 11:18 PM, NamoRamana said:

    I was wondering if MARS can ease this server migration?

    - in MARS, can I install multiple resources under the same server ? Idea here is that, each com server dll will act as own resource and its public methods will be the endpoints. For the better code management, is it

    possible to keep each resource code in its separate delphi project? how complex will be the installation of the REST server and these multiple resources, if we host them in IIS?

    - in current COM servers, Many of the method calls make heavy use of OleVarients as input and output paramas. Is there anything in MARS/REST that can keep those method signature same ?

    - in current COM env, we see some heavily used components slow down the end-user response a lot (sometimes, we have to reboot the host server). Do you think, MARS based REST service can handle a lots requests to a resource(I don't have request numbers)?

     

    Hi, welcome to this forum and to MARS.

     

    I've worked in the past to some migration process from Datasnap to MARS (and from RemObjects to MARS too). One thing you could take advantage is that TMARSActivation class (quite the core of request / REST method execution matching) can be replaced / tweaked.

    This means you may change the way an http request is matched against the Delphi code to be executed to produce response. Or you may want to have a different strategy/parsing technology to fill REST method arguments from the request.

    Obviously this is not the easiest task in the world but may have a lot of sense especially on large projects (I've migrated large datasnap applications to MARS with minimal effort and reducing to the minimum changes in the methods code).

     

    Coming to your questions:

    1) MARS can expose multiple engine (1 engine -> 1 port). Each engine can expose multiple applications. Each application can expose multiple resources. Each resource can expose multiple methods (http verbs and sub resources). You can organize resources as you like (one resource per unit, for example). I didn't get what you mean with "separate delphi project". You can deploy MARS server in several ways including ISAPI for IIS.

     

    2) MARS serialization/deserialization mechanisms are designed to be pluggable so you can implement your own readers/writers to handle OleVariants as you prefer.

     

    3) I have knowledge of MARS servers used in heavy load situations. Numbers are not significative because they actually depends on hardware/storage/purpose of REST methods. If you are looking for extreme performance, I would take a look to mORMot. But in 99% of my experience MARS is fast enough and REST architecture may help you to properly deal with scaling and performance boosts.

     

    Sincerely,

    Andrea


  12. On 7/25/2019 at 11:08 AM, Mike_Lob said:

    Hi,

    First of all: Thank you for providing us with this wonderuful implentation of your Rest library Andrea. I'm converting my own API servers to work with your library since it's far more enhanced than mine.

     

    Hi, thanks for the kind words and sorry for the delay.

     

    On 7/25/2019 at 11:08 AM, Mike_Lob said:

    1. How can I enforce Attributes provided with GET or POST calls?

    I have read somewhere in your GIThub that it should be possible but I have yet to figure out how to do this.

    I guess you are referring to QueryParam like "sort" in http://localhost:8080/rest/default/query/EMPLOYEE?sort=LAST_NAME

    You can use the Required attribute to let MARS check for the parameter's existence before calling the REST method.

     

        function GetDataset([QueryParam, Required] sort: string): TFDQuery;

     

    On 7/25/2019 at 11:08 AM, Mike_Lob said:

    2. How to dynamically change your database for a user.

     We have a Microsoft SQL server with a seperate database for every client.

     We also have one common database where we need to validate credentials and it will return the databasename from the sql server.

     For example: A user authenticates with an API key that we provied to the customer. That API key is linked to the users database and the SQL server returns that database name where we have to connect to - to perform specific user database queries.

    <SNIP>

    But I feel this should not be done like this. Also the .Server param doesnt exist in this context.

    Please forgive me if you see any 'newbie' questions. I start learning Delphi 4 months ago and I have yet to discover all Delphi concepts...

     

    I would add a specific value in the user's token, indicating the DB to use. You'll set this value in the token at authentication time (via API key or regular login).

    You can see this thread for a similar approach: 

     

    Keep in mind that your situation (if you store the connection name to be used inside the user's token) it's easier as you can use a connection name like 'TOKEN_CLAIM_DBCONNECTION':

     

    [Context, Connection('TOKEN_CLAIM_DBCONNECTION', True)] FD: TMARSFireDAC;

     

    And MARS will expand that connection name to the value of the DBCONNECTION name stored in the Claims of your (JWT) token.

     

    If you need some fallback mechanisms or more dynamic behavior, follow the instructions in the "FireDAC Connections" thread I linked here above.

     

    Feel free to ask whatever you need, sorry for the delay in this reply but I am abroad with family (vacation time).

     

    Sincerely,

    Andrea

     

     


  13. On 5/16/2019 at 6:24 PM, Andrea Magni said:

    I believe (I need to replicate this and investigate a bit) the Accept header sent from Angular matches also some MARS XML serializer.

    Will let you know here as soon as I figure out what's happening.

     

     

    It turned out it was the wildcard in the Accept header to cause this.

    I just pushed a fix that should also apply to your case and you may no longer need to instruct the Accept header all the times.

    Branch: develop, link to the commit: https://github.com/andrea-magni/MARS/commit/b8d5768b65072ff403de3c60e17688e8e95b1d9a

     

    Sincerely,

    Andrea

    • Like 1
×