Option to pass id with body
Closed this issue · 3 comments
Great plugin, I love it so far. I would like some options around how the requests are built though, for example I had originally written my PUT api like so:
[HttpPut]
public async Task<JsonResult> Put([FromBody] T item) {
// ...
}
but after seeing the HTTP traffic from this plugin I had to change it to:
[HttpPut("{id}")]
public async Task<JsonResult> Put([FromRoute] Guid id, [FromBody] T item) {
item.Id = id;
// ...
}
For now this works great, but once I start adding validation rules I will probably need a ViewModel on the backend with an optional Id to support this request.
ah, sorry, i don.t quite get what you want
I think he wants to use Id in stead of id (differences in taste)? I'm also not sure.
After looking through the source again I suppose this might be in the wrong place. I'll clarify and move this to aurelia-orm. Currently a PUT request (from aurelia-orm) looks like this:
PUT http://example.com/api/user/123
[Body]
{ "firstName": "John", "lastName": "Smith" }
what I had wanted was this:
PUT http://example.com/api/user
[Body]
{ "id": 123, "firstName": "John", "lastName": "Smith" }
I read through the source and realized that currently if I use .update
I will actually get this, which will work just fine:
PUT http://example.com/api/user/123
[Body]
{ "id": 123, "firstName": "John", "lastName": "Smith" }
So wondering where my missing id was being knocked off, I took a look at the aurelia-orm source and found: delete requestBody[this.getIdProperty()];
I'd like to make this optional.