Outline

Now that users can create and login to their accounts, we need a way to retrieve their current data as well as update it.

Geting the current user's data

To get the current user's info. Required authentication token.

GET /api/user

Returns a User object

Updating the current user's data

Update to bio, pic, name, etc

PUT /api/user

Authentication required, returns the updated User object

Example request body:

{
  "user":{
    "email": "jake@jake.jake",
    "bio": "I like to skateboard",
    "image": "https://i.stack.imgur.com/xHWG8.jpg"
  }
}

Accepted fields: email, username, password, image, bio

Showing public user data for profiles

What if we want to view the profile of another user on our site? We don't want to expose their email nor allow others to change their password, which is why those API endpoints are private. We'll need to create API endpoints that will only expose public data about the user.

First we'll need to create a new object for Profiles:

{
  "profile": {
    "username": "jake",
    "bio": "I work at statefarm",
    "image": "https://static.productionready.io/images/smiley-cyrus.jpg",
    "following": false
  }
}
Getting a user's public profile

GET /api/profiles/:username

Authentication optional, returns a Profile

The other actions we can do with a profile is to follow and unfollow it.

Follow a user

POST /api/profiles/:username/follow

Authentication required, returns a Profile No additional parameters required

Unfollow a user

DELETE /api/profiles/:username/follow

Authentication required, returns a Profile No additional parameters required

 

I finished! On to the next chapter