is angularjs working with database or json? - 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.

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.

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 there a way to not show API's JSON response to anyone?

So I have Angular 5 as the frontend framework and Node.js's Loopback framework in the backend.
Angular makes the API calls to Nodejs.
Is there a way to not show my JSON response to the public (maybe hiding it or not hiding but encoding it)?
Any ideas? Does anyone do it? What is the best practice?
I don't want anyone to know seeing my JSON what database structure I have or what the column names are.
Simple answer, no.
It's the terminology of Internet, user is able to see what request he sends to the server, and what response server returns to him. You could maybe encrypt the data with a key that you decrypt inside your Angular code, but ambitious people will find the key and you're returned with same thing.
As for the database structure, restructure your backend so keys from JSON don't represent the db schema. And I don't know why is this bothering you in the first place? If your API is secured properly, you have no worries about users seeing your JSON.

Creating a REST API for static hosting

I know this sounds crazy, but I had a thought and I was willing to try it out. I use GitLab pages for all my online projects, but a lot of them are ASP.NET MVC, which is an issue as I don't think you can run ASP.NET MVC sites on GitLab pages. I then thought, what if I make a site using something like angular or node.js, and have a central API for all my web projects? I thought that was a great idea, until I realized I couldn't use a database either. I guess what I'm asking is, would it be possible to create a REST API that uses JSON files for storage and node.js as the request pages, to create an API without a database?
Of course.
If you think about a database from the perspective of your application code, it is basically just a place to store and retrieve data.
Imagine the database library you are using has two simple methods, store and retrieve. In your application code, you could write db.store('here is the item') and the later on, db.retrieve().
However, those store and retrieve methods could be implemented in many different ways to provide the same effective behavior from the perspective of your application. Some examples:
Send/query the data to/from an external data store, such as PostgreSQL
Write it to a file on disk and read it back later
Store the data in memory
Make HTTP requests to an external system to store the data
Some of these options will be more or less appropriate depending on your exact requirements, however, the general idea is that given a database API, you could implement the exact same method signatures with a completely different approach.

How to make JSON response from server side

i would like to ask this for my second project of web apps, we were told to design and create javascript app that gets the information from a pre-defined database, and allows to add more data to it, modify it, erase any register, and search. That's pretty easy, but the thing is that our teacher asked that in the moment the browser makes the query to the server and this access the database, the server should return the response in form of a JSON.
I do not know how this is done, thats why i'm asking for a bit of assistance, since i always saw JSONs like libraries that can be add to a Javascript app.
You should pick a technology for creating a web accessible server api.
One common one in the .Net world is WEB API. You can also look into NodeJs (maybe using Express).
Json is really just a data format. It serves the same role as xml, but using a different notation.
Some frameworks like Asp.net Web API do content negotiation and returns data in the format requested in the http header (content type). Other solutions might require you to manually serialize the return data into JSON.
Link http://www.asp.net/web-api