Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send a GUID to a web api webservice

I am extending ApiController for a webservice.

The service takes a GUID as its only parameter. This is the url that I type in

/api/texts/2ADEA345-7F7A-4313-87AE-F05E8B2DE678

However, the Guid never reaches the Get method.

If I set it to object

public Object Get(Object userId)

the method fires, but userid is null.

If i set it to guid

public Object Get(Guid? userId)

I get the error

No action was found on the controller 'texts' that matches the request.

Does anyone have a sample that could help me?

like image 245
Nick Avatar asked Jan 29 '14 22:01

Nick


1 Answers

I suppose that you are using the default route in which the pattern is:

api/{controller}/{id}

So try naming your parameter accordingly:

public TextsController: ApiController
{
    public HttpResponseMessage Get(Guid? id)
    {
        ...
    }
}

Now the /api/texts/2ADEA345-7F7A-4313-87AE-F05E8B2DE678 url should hit the Get action on the TextsController and populate the id parameter.

like image 100
Darin Dimitrov Avatar answered Sep 28 '22 08:09

Darin Dimitrov