Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Farishta Jayas

Using Rest API to get data on website from the Database

Recommended Posts

Normally your website communicates with some backend service over REST. The backend service communicates with the database. You website doesn't communicate with the database directly (for security, among other reasons)

 

For example your website makes a GET call to the "/customers" endpoint to get all customer. The backend does whatever it has to do to get all customers from the database, converts that to JSON and then returns a JSON array containing all customers to the frontend. The frontend doesn't deal with the database directly. The backend often has additional logic e.g. to verify the current user has permission to get all customers and so on.


Remember to quote or @mention others, so they are notified of your reply

Link to post
Share on other sites
Posted · Original PosterOP
On 4/12/2020 at 12:14 PM, Eigenvektor said:

Normally your website communicates with some backend service over REST. The backend service communicates with the database. You website doesn't communicate with the database directly (for security, among other reasons)

 

For example your website makes a GET call to the "/customers" endpoint to get all customer. The backend does whatever it has to do to get all customers from the database, converts that to JSON and then returns a JSON array containing all customers to the frontend. The frontend doesn't deal with the database directly. The backend often has additional logic e.g. to verify the current user has permission to get all customers and so on.

I see. I figured that I asked the wrong question. I just needed to find out how to make http requests. Thank you!

Link to post
Share on other sites
5 hours ago, Farishta Jayas said:

I see. I figured that I asked the wrong question. I just needed to find out how to make http requests. Thank you!

So by asking that i guess you have zero experience with web development. Can you tell us more about your structure ? what technology run front and back end or if easier what language does frontend and back end uses ?

Link to post
Share on other sites
Posted · Original PosterOP
On 4/13/2020 at 6:16 PM, Franck said:

So by asking that i guess you have zero experience with web development. Can you tell us more about your structure ? what technology run front and back end or if easier what language does frontend and back end uses ?

Yes, I am very new. It's school project. The backend uses Python and the frontend is being done via a mixture of bootstrap, HTML, CSS and JS. 

 

Link to post
Share on other sites
28 minutes ago, Farishta Jayas said:

Yes, I am very new. It's school project. The backend uses Python and the frontend is being done via a mixture of bootstrap, HTML, CSS and JS. 

 

Then i assume the webpage are server with django or something like that ? Anyhow your easiest path is to simply do AJAX call. You query with AJAX a specific path that you receive the POST containing the method and parameter and it simply output the results. You can find many simple tutorial on the web for this. Setting a simple one up take about 30 minutes for someone new to this.

Link to post
Share on other sites
Posted · Original PosterOP
5 hours ago, Franck said:

Then i assume the webpage are server with django or something like that ? Anyhow your easiest path is to simply do AJAX call. You query with AJAX a specific path that you receive the POST containing the method and parameter and it simply output the results. You can find many simple tutorial on the web for this. Setting a simple one up take about 30 minutes for someone new to this.

Thank you very much Franck. I was able to find the solution. 

Link to post
Share on other sites
On 4/12/2020 at 11:27 AM, Farishta Jayas said:

I was wondering if anyone could help me understand how to make my website communicate with the database using Rest API

I know django, so i can tell you how to make a rest api.

Django has ORM(Object Relational Mapping) where objects created of a certain class can be migrated to PostgreSQL and then by using a module called djangorestframework you can easily make an api

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×