Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

connecteev's avatar

Designing an API to mash up public and private data

I have a Laravel application with logged-in users, posts, comments and likes (reactions).

I am designing an API to return all the data for a post (similar to this page here ). As you can see, the currently logged-in user can like / react to the main post, or any of the comments.

In my API, I return the post data, and the recursive comment data. However, I also need to know whether the currently logged-in user has "liked" (reacted to) the main post, and to the comments that are returned by the API. How would you design this API?

  • Should this be a GET or POST API?
  • Should it be "gated" by an Auth gate?
  • What would the API signature look like?

Note that this API is going to be used to retrieve data about the post + comments + reactions, and the user could either be logged in or not logged in.

Thanks in advance for your input.

PS. I don't care all that much about it being a RESTFUL API, as long as it is secure and gets the job done.

0 likes
3 replies
shez1983's avatar

for cache purposes I would have a post/comments api call and a separate one for likes. - you could combine the two but cache wont be that effective because then for one post & its comments.. each USER will have its own cache but if you have two api calls (one to get posts/comments) and one for like.. the first one will be cached for all users..

Returning all comments for a posts is going to cause slowness as u r having to load all comments so that could again be split.. & paginated.

1 like
connecteev's avatar

@shez1983 great point about caching.

For "Returning all comments for a post" Paginating nested comments is tricky. What if you have comment #1 with 20-levels of nested comments (crude example)? Would a simple paginate() on the top-level comments be enough? How would you do this?

shez1983's avatar
shez1983
Best Answer
Level 23

that is tricky indeed. you could replicate what youtube does. get each comment with three replies then have a view more or something.. it can get complicated but doable.

in this case you would have two more apis. one to get paginated comments, another to get comments replies (paginated or otherwise)

1 like

Please or to participate in this conversation.