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.
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.
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.
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.
None
0 Points
2 Posts
Proper Endpoint Design Question
Feb 05, 2021 02:55 PM|beantownace|LINK
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.
All-Star
53101 Points
23661 Posts
Re: Proper Endpoint Design Question
Feb 05, 2021 03:36 PM|mgebhard|LINK
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.
None
0 Points
2 Posts
Re: Proper Endpoint Design Question
Feb 05, 2021 03:41 PM|beantownace|LINK
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.
All-Star
53101 Points
23661 Posts
Re: Proper Endpoint Design Question
Feb 05, 2021 03:57 PM|mgebhard|LINK
I still do not understand the problem or why it is messy. Deleting 3 different resources at once could be as simple as...
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.