How to create API in Java, what's the difference between controller and API in Java

I am little bit confused with the terms API and controller in Java. Does creating an API means, creating a project, classes, models, repositories etc...

2 answers

  • answered 2018-07-11 05:51 Joe

    you can use the annotation “RequestMapping” on the Controller ,then the Controller can be a API ,when you type the url and enter,the springmvc will find the corresponding Controller ,the controller will work and return something ,maybe view ,maybe json and then...

  • answered 2018-07-11 06:05 mallikarjun

    From wikipedia

    an application programming interface (API) is a set of subroutine definitions, protocols, and tools for building software. In general terms, it is a set of clearly defined methods of communication between various components.

    It can be your REST SOAP endpoints or piece of java library(jars) or a middle-ware etc to which other components or software's or libraries will communicate.

    From my perspective controller is a piece of code which will be used for controlling other actions in your API. Like a controller can redirect to your business logic based on the given URL or the action performed in a perticular component (e.g., button click on the JAVA GUI).