Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug Web API model binding

I've been working with quite some Web API projects now and find myself bumping into the same problem every time and that's when I do a POST or GET the value / model etc is null or I get a 404.

There is a checklist like: - did I use the correct content-type? - has routing been set up correctly - is the signature of the model that I'm posting really the same as the model that the endpoint accepts?

It would be nice if there is a trace one could follow where it fails. Now it just looks like a black box, you put something in and it works or not, if it doesn't: see checklists or SO.

Is there something that you can setup in Web API so you can debug the model binding process?

like image 442
Elger Mensonides Avatar asked Nov 11 '22 01:11

Elger Mensonides


1 Answers

I would implement action filter.

One of the methods that can be overridden there is :

public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)

In this action you can check the response status and if it is an error to perform all your checks

This article could be a good starting point

like image 145
Alex Art. Avatar answered Dec 28 '22 10:12

Alex Art.