Creating a REST API

Now we know how to create a web app using servlet classes. We know how to get user input, how to access a database, and how to handle user logins. But what if we want to support different kinds of programs instead of just a web app? What if we want to create a desktop application or an Android app? How do we provide access to our data for those programs without writing everything from scratch each time?


This is a companion discussion topic for the original entry at https://happycoding.io/tutorials/java-server/rest-api

Thanks a lot for the heads up. What if you had your REST API created on a different platform and you now want to add and work with it on Java

One of the nice things about a REST API is that they’re pretty language-agnostic. Once you have one in place, you can interact with it by sending HTTP requests from whatever language you want.

I’d recommend googling something like “Java send http request” for a bunch of results! You might also be able to find a library that handles a lot of the details for you. Good luck!

Thanks a lot I appreciate

1 Like

Hi,
From where did the ‘token’ variable appear as it has not been declared in the ‘login()’ function, and also it is been used in the ‘setPersonInfo()’ and ‘getPersonInfo()’ functions without being declared prior. Overall how is the token stored in the client’s web browser?
Thank you.

Also from where do we get the ‘btoa()’ function?

If you’re asking about the JavaScript code, the token variable is declared as a global variable, so it can be accessed by every function after it’s set.

The btoa() function is a standard JavaScript function. I’d start by googling “JavaScript btoa” for some references!

Oh i see thanks , and also if we want the user to be able to make requests from other pages do we then store the token value in a cookie or something like that since other pags wont have the token value?
P.S Your tutorials are amazing

1 Like

Sure, I think that would work.

And thank you very much! These Java server tutorials are getting a little stale, so I’ve been working through updating them. Hopefully I’ll be able to update this tutorial soon!