locked
Proper Endpoint Design Question RRS feed

  • Question

  • User-1047715743 posted

    Hello all,

    I am trying to think of the best way to handle this.   I have a Get, Post and Delete endpoint I need to use.   The Get endpoint I have a transport object that has all the fields I need to display for the user in one Model for example:

    public class CustomerRequest
    {
    public string CustomerAccount { get; set; }
    public string CustomerLocation { get; set; }
    public string CustomerGroup { get; set; }
    public string CustomerType { get; set; }
    public DateTime CustomerEndDate { get; set; }
    public string CustomerAddedBy { get; set; }
    public DateTime CustomerAddedDate { get; set; }
    }

    So for the Get endpoint I need all of these fields but then I have a Post to insert new ones and a Delete no update.

    For the Post I really only need all the field 'except' the CustomerAddedBy and CustomerAddedDate.
    For the Delete it is actually a composite key of CustomerAccount, CustomerEndDate

    What is the best practice for this as I am weary of creating different request transport models such as a CustomerRequest, CustomerAddRequest, CustomerDeleteRequest which each is actually an IEnumerable of these object.    Is there a better way I was thinking if I could use for the delete a IEnumerable Tuple but that then does not show the property names in Swagger etc. 

    Thanks for any advice on design.

    Friday, February 5, 2021 2:55 PM

All replies

  • User475983607 posted

    What is the best practice for this as I am weary of creating different request transport models such as a CustomerRequest, CustomerAddRequest, CustomerDeleteRequest which each is actually an IEnumerable of these object.    Is there a better way I was thinking if I could use for the delete a IEnumerable Tuple but that then does not show the property names in Swagger etc. 

    Do you want to delete a record that has a composite key?  If so, implement a route that has as many route parameters are composite keys.

    Use a POST action to delete multiple resources with one action.

    Friday, February 5, 2021 3:36 PM
  • User-1047715743 posted

    Thanks the thing I am trying to think about is having to create a different transport request for the delete endpoint where its 3 of the fields in the same model.  Just seems messy to create different request transport objects based on a subset of properties from the main Get transport model that has all if that makes sense.

    Friday, February 5, 2021 3:41 PM
  • User475983607 posted

    Thanks the thing I am trying to think about is having to create a different transport request for the delete endpoint where its 3 of the fields in the same model.  Just seems messy to create different request transport objects based on a subset of properties from the main Get transport model that has all if that makes sense.

    I still do not understand the problem or why it is messy.  Deleting 3 different resources at once could be as simple as...

    api/MyController/1/2/3

    Or call three different delete actions.

    Ultimately it depends on your business requirements.  I have many application where the GET populates an entire page of data from many different sources.  The logic within the page might only update a section. I just use a different object than the GET to do the update.

    Friday, February 5, 2021 3:57 PM