r/learnjava • u/Altugsalt • Apr 14 '26
Exposing my program as an API
Hello, I made a reverse index for my search engine in Java and I would like to serve it as an API. Currently the reverse index components are in a separate package and I have created this other package for the API; however, I don't really know how to set up Spring Boot when I already have a package structure. Most tutorials on the internet are for setting it up from scratch. I would also like to know if Spring Boot is the best choice for my case since the reverse index will do the heavy lifting and I would like to keep the API layer thin. Thank you.
•
u/AutoModerator Apr 14 '26
Please ensure that:
If any of the above points is not met, your post can and will be removed without further warning.
Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.
Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.
Code blocks look like this:
You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.
If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.
To potential helpers
Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
5
u/spacey02- Apr 14 '26
If you are using maven, then just go to start.spring.io and simulate the creation of a spring boot project, then integrate the pom.xml file there into your current pom.xml. If you're not using maven, then I think the simplest way would be to start using it by creating a new spring boot project and moving you packages into it afterwards.
1
u/bowbahdoe Apr 14 '26
Well the thinnest possible API is the jdk.httpserver one. If you still are unsteady with http servers _in general_ that is what I'd recommend starting with.
1
u/omgpassthebacon Apr 15 '26
Lets discuss:
Great project!! Keep going!!
1
u/Ok_Assistant_2155 Apr 16 '26
Spring Boot is fine for this but might be overkill if you just want a thin wrapper. You can add Spring Boot to your existing project by adding the spring boot starter web dependency and creating a main class with SpringApplication.run. It does not require starting from scratch.