r/learnjava • • Feb 08 '23

API, REST & RESTfull

what is the difference between API, REST and RESTful?

I was researching articles, blog and what I understood was: API is a ready-made application that can be implemented in your project. REST, an architecture that contains functions: PUT, DELETE, POST, GET, etc. RESTfull, and the application of REST.

But I'm still trying to understand what exactly an API would be? any coding that contains controller, service and model and an API?

Can I create a workshop API and then implement a front end layer on top?

44 Upvotes

17 comments sorted by

View all comments

4

u/nutrecht Feb 09 '23

API is actually a very broad term. It stands for Application Programming Interface. So where a Graphical User Interface is a way for people to interact with software, an Application Programming Interface is a way for applications to interact with software, other applications.

So:

API is a ready-made application that can be implemented in your project.

To a large extent, it's just not limited to 'applications'. Any software that is designed to be interacted with through other software, is an API. And even a GUI can be accessed as if it's an API; that's what 'screen scraping' does; software pretending to be a human accessing stuff through a browser.

In the more narrow context of REST API's; these are typically services that other pieces of software interact with over HTTP, and typically use JSON to serialize data. As an example, if we look at your user profile:

REST is a set of guidelines on how to design an API that can be accessed via HTTP, typically (but not limited to) using JSON. It's basic principles are to see data you access as resources. Similar how your profile page is a resource: https://www.reddit.com/user/CupHeap would internally for reddit be a path where CupHeap would be the ID of the 'resource' that is your user profile. So the main design principles for REST are:

To answer your questions:

But I'm still trying to understand what exactly an API would be? any coding that contains controller, service and model and an API?

Assuming the controller returns JSON, then yes. If your controller just serves HTML for users to see, it would generally not considered an API. But again; it's a very broad term.

Can I create a workshop API and then implement a front end layer on top?

Yes :)

Building API's in Spring is my bread and butter and I've been doing that for over a decade. Before REST became fashionable we used SOAP (which REST was a response to, because SOAP was a mess). Before SOAP was fashionable we just created our own formats and used direct TCP/IP connections ;)

1

u/maethor Feb 09 '23

Before SOAP was fashionable we just created our own formats and used direct TCP/IP connections ;)

Don't forget CORBA.