Spring Boot API - POST complete data from client - json

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

Related

how do i store and retrieve form data from a wesbite

this is probably something i could have googled; however i thought id start getting more active on chat forums so basically...
I'm almost done with making a family members business website, on the website is an enquiry form; i want to know how i go making that form store the data its given and how i would then retrieve that data?
still doing final touches to the design then im going to start learning the process of deploying it live which is why im posting here to see how to go about it.
It is very vast question, You will need an API to pass the data from Forms to API Server and a Database, that will store the data. It is also called client-server architecture.
Web Forms -> API Server -> Database
You can use either node express, java, python or any language to create API.
You can install the database on the server where you will run the API or you can use any from the cloud like AWS or Heroku, that way you will skip some setups and it will be ready to be used directly in the API.
To store data from an HTML form, you will need a server-side language and a database to save the data to. Some popular options for the server-side language include PHP, Java, and Python.
Once you have chosen a server-side language, you can use it to write code that will process the form data when the form is submitted. This typically involves connecting to a database, creating a table to store the data in, and then inserting the form data into the table.
To retrieve the data from the database, you will need to use a SQL query to fetch the data from the table. You can then use the server-side language to display the data on the website as needed.
It's a good idea to also consider security when handling form data. Make sure to validate and sanitize the form data to prevent any potential security vulnerabilities.

Connecting to MySQL directly through flutter application

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.

How to refactor route endpoints into ORM structure?

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

is angularjs working with database or json?

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.

Send computed data from client to server

i have created simple REST architecture using Jersey and Tomcat. I sent data from server (as a resource using "/get") to client and then customer makes some computation on this data. My problem is, how to send this calculated data from client to server ?
Since you're using a REST architecture, how to send the data back to the server depends on what this data represents.
For example, suppose you are dealing with users, a GET on /users is performed, so the client has the data, now
if the client changes something you might want to make it PUT on /users/:userid, the PUT here represents the fact that you are updating a user identified by userid
if the client does not find a user it might want to create it, so you might want it to perform a POST on /users with the user in the payload
This is just an example to briefly explain how it works, of course it depends on your case, if you need more help please update your answer adding details.