Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Akseli Hiltunen
Akseli Hiltunen
3,430 Points

Course/literature on how to implement Spring boot web app that consumes Spring REST api?

Hi,

On course Build a REST API in Spring (lesson Versioning), Craig mentioned that there might might be several clients consuming this API. Is there a course on Treehouse that teaches how to make a Spring boot application (like Giflib) that uses this approach or do you know such a course and/or literature somewhere else?

I'm specially interested on whether or not the API and web application should be separate programs or can I have a Giflib like application that also provides the APIs and itself consumes these APIs so that I can code the business logic to the APIs and just serve browsers and mobile apps from these APIs in the web application. Also, how does the user authentication work? If API is separate program, should the web application just pass the credential to the REST API?

1 Answer

Once you have your API with its business logic you can:

  • Make your own web frontend that uses the API
  • Make your own Android/iOS App, desktop application or whatever that uses the API
  • Allow other people to build their own frontend that consume the API

It's considered best practices in such a case to separate the frontend application from the API. It allows you to deploy them on different servers (often necessary to scale big applications in production), to make changes to one without touching the other, to have completely separate teams working on both, and so on. But you don't have to. With Maven you can use modules to have everything in a single project but still work on API and frontend as separate programs. I'm not sure how to do the same with Gradle.

However Spring Boot App would be used for the API part, not for the web frontend part. While it would be technically possible to make a Spring Boot App only to consume another API, it's kind of like using a hammer to drive a screw in a hole. Nowadays a javascript Framework such as AngularJS would be the most likely candidate to design the web frontend and consume the API. That's how most modern java based web apps are made. Look at this cool project as an example: https://github.com/Code4SocialGood

They have a cs4g-services repository for the API (Spring). They also have a web frontend (AngularJS) and Android and iOS apps, all of which consume their API.

I don't know of a course walking you through all of it, but there are AngularJS and other javascript courses on Treehouse that will help you design web frontends capable to consume any json API. It's definitely a very good thing to have in your skillset if you're looking for a full-stack job.

Oh, and I would add that it does make sense to use Spring Boot App if you consume an API and add your own logic to it. The weather app in this course does that: https://teamtreehouse.com/library/unit-testing-a-spring-application

That's not the focus of the course, which is about unit testing, but by looking at the code you'll still get to see how a Spring Boot project can consume an external API: https://github.com/treehouse-projects/spring-unit-test-weather

Akseli Hiltunen
Akseli Hiltunen
3,430 Points

Thank you so much Livia!

This actually answered my question perfectly and I really appreciate your effort.

I guess next thing I'll do is to look into AngularJS :)