Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Build a REST API With Express Completing and Testing the API Next Steps

Ceil-Ian Maralit
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Ceil-Ian Maralit
Front End Web Development Techdegree Graduate 19,422 Points

What really is the purpose of REST API?

Hi! Good day. I was just wondering, what really is the purpose of REST API? Like for example, does it improve the performance of your website, etc.? I did not finish the course because I can't seem to understand what its purpose is. Can someone please help?

Thank you!

3 Answers

stjarnan
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
stjarnan
Front End Web Development Techdegree Graduate 56,488 Points

Hi Ceil-Ian Maralit,

That's a great question! So to make it easier to explain, let's pretend that we have a database containing user information, posts and other cool things you might want to store. We also have the website/web app itself that the user will see, this website needs to be able to get the data from the database to be able to present the posts for the users and to make sure that the correct password is used to log in.

To get the data from and to the database, we use the rest API to handle post and get-requests from the website and complete the correct action. This way all the website needs to know is what request to make to the API, and the API will handle the rest.

Doing it like this makes a couple of things easier, examples could be:

  • You get a clear backend and frontend, the backend will take care of things like getting and sending data from and to databases while your frontend will decide what to show to the user and what to do with the information received.

  • You could use the same API for your mobile apps as for your web apps. Or you could create the same app in Angular, Vue or React and it would be able to work with all of them without changing the API!

To sum it up, using Rest API's provides you with flexibility, scalability and simplicity (among many advantages). I hope this helped you and motivated you to get back at it.

Jonas

Ceil-Ian Maralit
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Ceil-Ian Maralit
Front End Web Development Techdegree Graduate 19,422 Points

Wow. Thank you so much for this answer. Before, I was looking for something that will like really define what back end is to me.. Thanks to you, you made me realize that.

Yeah, I was really having a hard time getting the main concept of what I'm studying so I stopped for a while. Now, I know that it is more powerful cause I am familiar with express which is very good.. I'm gonna go back studying it to be a full stack developer. But, really. Thank you so much! :D

Ceil

A practical example is a hotel website that lists real time weather updates for guests wanting to visit the local beach.

They could go to Weather.com and look at that info, or they could just go to your hotel website and see the info there because you’ve pulled the info from the API to make it accurate for your guests.

Another example is grabbing traffic information to know where certain vehicles (think planes or trains for example) are at a given time.

I think really this API that we built was just poor planning on Treehouse's part. We should've done an API that makes sense, like how we would use an API from a major website everyone knows.