Reputation: 2059
I'm trying to get to work my project on ASP.NET Boilerplate.
I'm right now creating Dynamic Web API and here is what I have:
My AppService:
public interface IBorrowLendAppService : IApplicationService
{
GetBorrowLendsOutput GetBorrowLends(GetBorrowLendsInput input);
}
My Input:
public class GetBorrowLendsInput : IInputDto
{
public byte ItemType { get; set; }
public int PersonId { get; set; }
}
And here's my problem:
When I'm invoking a method [GET]GetBorrowLends without any data I'm receiving error:
{
"result": null,
"success": false,
"error": {
"code": 0,
"message": "Your request is not valid!",
"details": null,
"validationErrors": [
{
"message": "input is null!",
"members": [
"input"
]
}
]
},
"unAuthorizedRequest": false
}
When I'm trying to invoke it like:
.../GetBorrowLends?ItemType=0&PersonId=1
I'm receiving same error
Invoking [POST] with data:
{
"input":{
"ItemType":"0",
"PersonId":"1"
}
}
Returning another error:
{
"result": null,
"success": false,
"error": {
"code": 0,
"message": "An internal error occured during your request!",
"details": null,
"validationErrors": null
},
"unAuthorizedRequest": false
}
How do I handle that? And how to create GET/POST methods manually?
Thanks
Edit:
I have handled problem with not working endpoint. I have wrongly set 'Content-Type' parameter in POST message.
But question about GET/POST methods in ApplicationService is still open.
Upvotes: 4
Views: 3596
Reputation: 3644
The default HttpVerb is set to Post.
/// <summary>
/// Default HTTP verb if not set.
/// </summary>
private const HttpVerb DefaultVerb = HttpVerb.Post;
Then there is a method in IApiControllerActionBuilder
to change the verb of an action.
IApiControllerActionBuilder<T> WithVerb(HttpVerb verb);
You should be able to change the verb with the following call (in Initialize
of your WebAPI module)
DynamicApiControllerBuilder
.For<ITaskAppService>("tasksystem/taskService")
.ForMethod("SomeMethod").WithVerb(HttpVerb.Get)
.Build();
Further information could be obtained on the website.
Upvotes: 2