Modelling an user invite with JSON API


#1

Hi,

I’m new to JSON API and I got a user invite problem at hand I don’t know how to model correctly.

The scenario is the following: My application has teams and registered users can be invited to join a team, registered users get a link to the invite, and they can either accept or reject the invite. If an invite is accepted, a new membership for the team will be created.

At the moment I have four resources:

  • Users
  • Teams
  • Memberships
  • Invites

I currently support CREATE and DELETE for invites. How would you model the accept and reject actions? I used to break the CRUD principle there and just add two member functions accept and reject to the invite’s resource controller.

What I find particularly tricky is that when an invite is accepted, a membership resource will be returned.

My questions are:

  • How would you structure the resources to accept the invite?
  • How to let the client know “how” it can accept the invite, i.e if the client calls READ /invites/:invite_id the response should point the client to where he can exchange the invite for a membership.

Thanks a lot in advance,

Simon


#2

On the face of it this seems reasonably simple.

  1. A Team resource has an invitations relationship that allows invitations to be created (e.g. via a URL like `/teams/:team_id/invitations).
  2. An Invite resource has a membership relationship that allows a membership to be created (e.g. via a URL like `/invitations/:invitation_id/membership), i.e. accepting an invitation = creating a membership, declining an invitation = deleting the invitation

What problems do you foresee with that approach?