9.2: Retrieve Followees in API
Next, we'll add functionality to retrieve a list of User
s another User
has followed. We'll do this with query parameters, although you could do it using a separate endpoint.
Update UserParams
In the UserParams.cs
file, add two properties: one for Followers
and one for Followees
. Both will have a default value of 'false'.
Update UserService
In UserService.cs
- first we'll add a private method to retrieve either the followers or followees of a user.
If there is a parameter for 'followers', we'll return all of the users that are being followed by the user with the passed in id.
If not, we'll return the users that are following the user.
Next, in the GetUsers()
method we have already written - we'll add checks for query parameters for followers or followees being passed in:
Testing in Postman
Now, if we send a GET
request to /api/users?followees=true
we should get back the user we previously followed while testing:
Last updated