You are not logged in.
Pages: 1
Thanks @ab.
I used it(OnBeforeBody) to create the whitelist and work fine.
Do you have any suggestions for adding and removing routes after starting the server without stopping it?
Since many methods of `THttpProxyUrl` are defined as `protected`, I cannot use them in my class. It seems I have to add a function for this in the `mormot.net.async` unit.
I couldn't find a solution to dynamically create a whitelist of IP addresses.
Thank you @zen010101
I just didn't understand about the whitelist.
Hello,
I'm working with a THttpProxyServer.
I know I can add directories to it before creating the server. (settings.AddFolder(folder, url);)
1)What I'd like to know is how to dynamically add directories and map them to URLs after the server has been created and started?
2)Additionally, does THttpProxyServer support an IP whitelist? If so, how can I modify this list after the server has started?
Thank you, @Thomas.
I’m trying my best to read the answers carefully, but since English isn’t my native language, I don’t fully understand everything, and sometimes I even explain things poorly.
I apologize for that. I will try harder and ask fewer questions.
Thanks, @igors233.
I’m using SQL Server 2008 for the database.
I’m also using JWT and username/password for authentication.
I have an existing API written with HORSE, and I wanted to rewrite it with mORMot.
Additionally, I want to use the ORM feature of the mORMot framework in this rewrite (I have prior experience using TMS Aurelius).
The first challenge for me was understanding the different servers in mORMot, as I wasn’t sure which server is for what.
The second challenge was connecting it to SQL Server.
I haven’t yet tried JWT and authentication.
Regarding the servers, I realized that when I use TRestServerDB, the user or client can easily access the tables. Authentication might prevent this access, but from what I’ve studied, it doesn’t seem to check the access details. For example, imagine I have a "status" field that marks records as deleted (without physically deleting them). In the method for listing data, I don’t send these records, but since the client has access to the table through ORM, they can retrieve those records.
Also, when I use TRestServerFullMemory, I no longer have access to the ORM.
When I switch from TRestServerDB to TRestServerFullMemory, how do I access the database?
Do I have to abandon ORM in this case and revert to the old method of database access?
I think I was a bit confused, but I understand now.
No, I don't want to keep the tables in the original TRestServer model.
You have run so many marmot tests and everything is clear to you. It's not that clear to me.
I've modified the server by setting
HttpServer := TRestHttpServer.Create(HttpPort, [], '+', useHttpApiRegisteringURI,4);
, but my Delphi client can no longer connect to it.
I reverted the previous command to its original state and made changes to the service.
I modified the class from 'TProductServer = class(TRestServerDB)' to 'TProductServer = class(TRestServer)'.
However, I'm getting an access violation error at the line 'ServiceDefine(TProductService, [IProductService], sicShared);'
I really don't know where to delete the model from the server.
I've been unable to locate a solution to prevent direct access to the ORM.
It would be convenient if the server offered a method named AllowDirectAccess. :rolleyes
It was interesting talking to them, but it didn't help me.
Thank you.
I changed the interface name.
It's giving the error:
Project TestServer.exe raised exception class EHttpApiServer with message 'HttpSetServiceConfiguration failed: ERROR_ACCESS_DENIED (5)'.
But the database and table are created. (I also added the command ProductServer.Server.CreateMissingTables;).
Is this error a known occurrence?
What steps should be taken to rectify this error?
---Edit
I have also successfully modified the list method.
Is this the right and proper way to do this?
function TProductService.List(var AProduct: TProductParam): RawJson;
var
Sql: RawUtf8;
begin
Sql := 'select * from Product';
Result := TRestServerDB(Self.Server).DB.ExecuteJson(Sql, True);
end;
How do I disable ORM for the client?
Currently, there are commands like :
http://127.0.0.1:8080/root/Product
http://127.0.0.1:8080/root/Product/1
are returning records without any filtering or validation
I use SQL but I never use foreign keys. I always manage table relationships myself. I think foreign keys are more of a hindrance.
I think my way of categorizing units into Controller and DAC is not very suitable for Mormot.
I should choose a different structure for categorizing files in Mormot.
Do you categorize your files in a specific way?
My next question is how to implement the List method to return the list of desired records to the client?
Thanks
Thank you.
I changed the interface name.
It's giving the error:
Project TestServer.exe raised exception class EHttpApiServer with message 'HttpSetServiceConfiguration failed: ERROR_ACCESS_DENIED (5)'.
But the database and table are created. (I also added the command ProductServer.Server.CreateMissingTables;).
What is the reason for the following error?
Project TestServer.exe raised exception class EServiceException with message 'TServiceFactoryServer.Create: IProduct routing name is already used by a Product SQL table name'.
My test Project source
https://mega.nz/file/d5RTDB5A#f-mBchZj4 … a826ZtybbA
I haven't assigned the model to TRestHttpServer.Create yet, but the problem doesn't originate from there.
I finished reading BeDelphi2014 today.
There are still some things that are unclear to me.
My first question is:
Has the syndb unit been removed from mormot2?
In the examples, I only saw connections to SQLite. What should I do for MSSQLServer?
Which units should I add?
Previously, when accessing the database,
I created a connection and then closed it after retrieving the data. (In the events related to creating and destroying the class) And apparently here, when the server is running, the connection is created and remains open until the end of the server.
Well, that's right. I hadn't thought about the FP.
In the unit 'mormot.core.variants', the unit 'mormot.core.base' is called,
which in turn calls 'variants'. However, the IDE mistakenly identifies it as 'mormot.core.variants'.
While this is indeed an IDE error (Or an unintentional setting in the IDE) , the easiest way to prevent this is to use 'system.variants' instead.
@ab
I downloaded the new version of mormot2 yesterday.
In the mormot.core.base unit at line 36, the unit variants should be changed to system.variants.
Because it's giving a Circular unit reference to 'variants' error.
(Delphi 12.1)
Thank you. I will try it
I'm not sure I understand correctly.
Do you mean I should write an application server on a server and have an API connect to it as a client, retrieve database information, and then act as a server itself to send the data to the client (user side)?
I've been using Mormot for a long time and it was really difficult at first.
If I can give one piece of advice, don't mix the ORM layer with the API layer.
Create ORM classes just to interact with the database.
Create another layer of classes (DTO) for your api or business rules...
With your DTO you can return whatever you want in your api without any relation to ORM, making it much cleaner.
Thank you for your explanation.
I generally prefer to keep the ORM and API layers separate. I'm not sure if this would cause a performance decrease.
I've been busy with other things for a while, but now I'm back to learning about Mormot. I want to create methods both with and without Models on a single server, and connect to it using a client.
I hope this isn't too difficult and I'm not bothering anyone.
Thanks @ab
Thanks @edwinsn
Thanks @rdevine
I think I'll be busy with this for a few days.
The question that's on my mind is whether it's possible to have multiple ORM models, multiple JSON outputs from the database, and non-model methods in a single API.
Thanks @edwinsn
I am determined to learn mormot2. I can use it with the help of examples, but I wanted to understand how it works. I have a lot of questions on my mind and I hope to find the answers soon.
It would be great if this forum had a "thanks" button for posts.
Orm model can have no objects;
I understand. So in any case, the model must be created, but the model can be empty and not contain any objects.
Thanks
Why is this a problem?
With best regards
Thomas
That's not the problem.The problem is how to do it.
APIs can generate different types of outputs.
For example:
A method that simply returns a number as the API version.
A simple method (like ping) that returns a simple value (for testing connectivity).
Up to complex methods that return a record or records from a database.
Or even files or streams.
Therefore, an API needs to be able to access all types of methods.
I reviewed the mormot2 examples. In the examples, everyone uses the model.
I've looked through the v1 documentation as much as I can, but I'm still not sure how to connect to the TRestServerFullMemory server for communication on the client side when I'm not using a model and orm.
I used TRestHttpClient and set the model parameter to nil. But I get an accessviolation error in the ServiceDefine instruction.
Thank you. I fully understood how to use the interface without using orm.
I have a problem with the client. If I don't understand, I will ask.
Thank you.
I have created a new record for the output, but the JSON output contains both the input record and the record I defined for the output. What can I do to prevent the input from being sent in the output?
Also, how can I test this with Postman?
I tried several URLs in my Postman request, but the inputs are not being received.
get : http://127.0.0.1:8080/api/Calculator.Add/?Data={N1:1,N2:2}
post : http://127.0.0.1:8080/api/Calculator.Add
body-raw : {Data={"N1":1,"N2":2}}
Based on what I have learned, I wanted to create an interface-based server.
I do not want to use ORM on my server. That's why I did not create a class for orm and data.
The program stops with an error and I don't understand why.
---I have removed the code to comply with the rules.
Thank you for your responses, friends.
I understand that there are three ways to work with mORMot:
1 - The REST ORM
2 - Methods-based services
3 - Interface-based services
I also didn't understand how to create multiple routes for my API. What I did was look for the route name in the URL in the OnRequest event and execute a function.
I also tried to use the route and router properties in the following way, but it didn't work:
fHttpServer.Rout.Get('Ping',Ping);
fHttpServer.Router.Get('Ping',Ping);
Thanks for your guidance, friends.
I know enough to build a simple server and use a websocket with it.
I'm looking for the basic concepts and principles to have a good understanding of its structure in order to create a large system.
I've already written five large APIs with Horse. Recently, a friend of mine mentioned that mormot v2 has changed a lot. It is very fast. That's why I decided to write the new API with mormot. But I have a superficial understanding of it. I would like to know how to get the most out of it.
Hi,
The main point I'd like to make is that there is no documentation or guide for learning the basics of this framework.
There are only references from the website to GitHub and back again. In the end, you can only look at the sample programs!
It's very frustrating that there is no explanation of how to work with this framework from the ground up.
Pages: 1