educative.io

[API Design] Subscribe / Unsubscribe to a channel

I was wondering which CRUD operation should we use to design an API that provides capability to subscribe / unsubscribe to a post/channel/content.
Open to suggestions.

Hi, @Sundeep_Kumar
We can use the POST method to subscribe to a post/channel/content as there is a many-to-many relation between a user and a channel because many users can subscribe to a channel, and multiple channels can be subscribed by one user. So To create a subscription, you can use the HTTP POST method. Clients can request the API endpoint with the necessary information, such as the user ID and the post/channel/content ID to subscribe to. The API will then create a new subscription record in the database.

To unsubscribe or remove a subscription, you can use the HTTP DELETE method. Users can send a request to the API endpoint, specifying the subscription ID or the user ID and the post/channel/content ID to be unsubscribed from. The API will locate the corresponding subscription record in the database and delete it.