I'm not even sure exactly what constitutes an endpoint and how to turn it into ORM. I'm new to Angular, but from my understanding an endpoint is when you get data from a server, be it an online API or a database query using SQL.
From my research, ORM basically makes the code more high level and gets rid of the need for SQL, but how do you do it? And what if there is no SQL, and it's a request to an online API using a URL?
For clarification, I am working on a website that uses Angular. There is a database, an API, and a UI, and the API pulls data from online APIs and from the database. So my question is about how to refactor both types of endpoints.
ORM is a way to work with objects and let a framework take care of converting the object into a way required for the DB or data from DB to objects. UI has nothing to do with it. It is only a concern of the data layer or data tier of your backend. May be we can go on and say that even the controller part or others of your backend need not be aware of the ORM.
So the abstraction you have is
Irrespective of type of DB you talk in terms of your Model classes
Whether the data comes from DB or from another online API call by backend, finally it will also be a model object and can be sent to UI
The UI layer need not or should not know how your backend is getting the details that is required for UI. so the structure should be based more on Common sense, domain, your requirements etc and not on how backend acquires data.
And the same applies to API endpoints too. Create them in a meaningful way for your application. Example:
// this might be some of the endpoints required for a e commerce site
/product/recommendations // returns recommended products for a user
/product/categories // returns categories of products
/user/getCartItems // returns cart items of user
/orders/cancel // cancel a order
see how the api endpoints are completly unaware of how backend handles / retreives the data
Related
Can someone explain to me why you can't connect to a MySQL DB directly through dart from a security point of view?
There is no hard guideline on whether to connect frontend directly to backend or not. It is just a design practice that has been widely accepted and evolved over many years.
Typical app structure consists of
FRONTEND -> SOME MIDDLE LAYER -> BACKEND
Where your middle layer handles all the interactions/processing with the database and the frontend uses this functionality with some sort of API structure. Having this layer is extremely helpful when the application goes to scale, it gives an added abstraction to the frontend.
It is not advisable to directly fuse your frontend(your flutter app), to the DB(MySQL) because any efficient hacker might use basic man-in-middle attack to know your DB structure/connections/queries(There are some pretty effective decompilers present out there), and alter your data and you might not even get to know what caused the data to update unless you've applied some checks on DB layer.
Also, your frontend logic needs to be more of end-user centric than to handle the data of the user. Any backend system(java, node, etc) gives you added functionality & freedom to parse and present the data from either side.
You can use the sqlite package available to store basic data, like your session tokens, your app configurations etc, but it is advisable to keep the main user data like the logins, etc in a separate place, or better yet, you can use the firebase plugin to store data in document structure in the cloud.
I want to implement a method to get a nested objects (40 nested Object JSON format) and apply some businesses on objects, then insert those in some tables.
Is a good way to get all data objects in one web service method, or write some separate web service methods to get data and break input nested objects?
Is there any standards to implement web service?
Can any one introduce any books or articles to explain standards of web service implementation?
Thanks.
You really need to decide yourself whether the infrastructure (e.g. network connection, server capacity) can handle the "large" dataset and whether it is useful for your consuming clients to receive all of the datasets (they might need only a part of it most of the time).
If say 80% percent of the time it's a subset, you can return that subset and the rest of it you can use HATEOAS.
Those are just links where the client can direct themselves to if they need data which was not sent in the initial call to your API.
I have the task to implement an API with Spring Boot and a relational database to save the data from a client (mobile app) and synchronize it.
So far no problem. I have some endpoints to post and get the stored data.
Now I have the task to provide an endpoint that return the complete data in a GET-Request and another to save the complete data of the client via a POST-Request.
My problem is:
How do I store the complete data in one POST-Request(JSON)?
The database has multiple entities with manytomany relationships and if I just POST them then I have some problems with the relations between the Entities.
My approach to GET the complete data was to just create a new Entity with every entity in it. Is this the best solution?
And is this even a good solution to POST the complete data instead of the usage of the other endpoints to get the entities one by one. Or is there another approach to store and restore the complete data from server and client? Whereby I think that posting the complete data makes less sense.
is this even a good solution to POST the complete data instead of the usage of the other endpoints to get the entities one by one
In some scenarios you may want to force update or synchronize the client data with the server, for example, WhatsApp backup now option.
How do I store the complete data in one POST-Request(JSON)
You can make one post endpoint that extracts the data sent from the client and internally use all your repositories or daos for each property.
My approach to GET the complete data was to just create a new Entity
with every entity in it. Is this the best solution
either by doing as you mentioned or by handling it manually in the endpoint like this
also check this one which uses apache camel to aggregate multiple endpoints
This may be a total shot in the dark, but looking for a service that basically exposes a database model as a restful service which we can query from the front-end (eliminating the need for a middle layer/server).
The idea would be simple enough, create a database with say a products table. This would then be exposed automatically via an API that represents that table. On your front end the user could enter text or choose several options and then via JS you could hit that endpoint (with the user's choices as parameters which inevitably becomes a SELECT and retrieves the data), that returns some JSON back in the form of results and via JS you display it on the front-end.
I have to believe something like this exists and maybe I am not being clear enough, but its basically an auto-created backend. This would be great for rapid prototyping.
Thanks in advance if anyone has ideas!
I am developing web application. I am getting data in json or database. I can use this data in angularjs at one time (i think so). So if any data changed in json or database then angularjs should work .Is this how it normally works? Is it possible?
thanks in advance.
Yes and no. When we say data binding in Angular JS, we are referring the data in memory and manipulations we do to the data. For instance when we type in text field, we update a javascript object, and then display it in another form on the browser.
When dealing with external data, e.g. json or database, we will need to fetch that data from the server. Browser on the client side won't know that json has been changed in the server, it needs to send a request to the server to fetch new data. After the data is loaded into memory, then we can do the same manipulation and display it.
The remaining question is when to trigger the data refresh. Well this is not an easy question for web application if you are using restful API. It can be reactive like when user do specific action, or refresh at fixed interval, depends on your requirement. I heard that socket programming is good for this kind of thing but I'm not expert in it so I'll leave it to others.
Angular apps usually manage their data using RESTful API endpoints. This means, that your Angular app communicates (usually via JSON) with a backend application running on a server, which handles all database interaction.
In practice this means that to get for example all blog articles, in your Angular app you would do a $http GET request to api.yoursite.com/articles. Then your backend application does database query and returns a JSON with all the articles.
Does this answer your question? Because it wasn't clear what exactly you were asking.