In this tutorial, we would would outline the steps to Build a REST API. We would also plan the various components of out REST API.
As a reminder, an API(Application Programming Interface) allows exposes functionality of an application to other applications. So as a programmer, you’ll spend most of your time building APIs.
- About the API we’ll Build
- Create the User’s Class
- Create the Location Class
- Create the Post Class
- Watch the Video
1. About the API we’ll Build
So we would build an API for a social network platform. Let’s call it SocialAPI. This is like a mini Facebook! Although it is small, this is the same principle social networks follow.
Our SocialAPI would contain the following classes:
- list of users
- list of locations
- list of posts
Also, the following relationships would be supported:
- a user has a location
- each location could have 1 or more users
- a user could create a post. Hence each user can have one or more posts
Our SocialAPI would support the following operations:
- add, delete and update user details
- add, delete and update location details
- add, delete and update post details
- get a list of users or locations
- get user or location by id
- get list of posts for a particular user
The entity relationship diagram for our SocialAPI is shown below.

2. Create the Users Class
- First you need to create a package that would contain the User class
- Then, inside package create a class and call it user
- The content of the User class is shown below. So you can copy and paste. You can also type it out yourself
package user; public class User { private String id; private String firstname; private String lastname; private Location location; private String email; }
After you have added this code, then you can generate the getters and setters.
3. Create the Post Class
- First you need to create a package that would contain the Post class
- Then, inside the course package create a class and call it Post
- The content of the Post class is shown below. So you can copy and paste. You can also type it out yourself
package post; import user.User; public class Post { private String id; private String postdate; private User user; private String details; }
Again, remember to generate the getters and setters for this the User class
4. Create the Location Class
It follows the same process
- First you need to create a package that would contain the Location class
- Then inside the location package create a class and call it Location
- The content of the Location class is shown below. So you can copy and paste. You can also type it out yourself
package location; public class Location { private String id; private String name; }
Also remember to generate getters and setters. You can watch the video below to see how you can do this.
So at this point, you have successfully set up the structure of the SocialAPI. So in the next lesson, we would add service to get list of items.

In the user class, don’t we need to import location.Location like you imported user in post class?
Hey,
I would like to thank you for your time and effort making these tutorials.
I have a question. I get an error when I use; User user1 = new User(S,S,S,L,S);. It says I need constructor. How can I fix this, please?