-2

New to ServiceStack. I set up some services and many are working fine. However i have a Get Request that for some reason does not hit my Service. I can hit a Get that returns the List but not the Service to return a specificID. Postman call just returns a status of OK.

Here is my request Class

  [Route("/InspectorIDRequest/{InspectorID}", Verbs = "GET")]
public class GetInspectorIDRequest
{
   public int InspectorID { get; set; }
}

Top Method in my Service works with a call to First Get hits with call

  http://localhost:50238/Inspector

Second Get never gets hit with call

 http://localhost:50238/InspectorIDRequest/?InspectorID=2

Here is my Service

    // Returns a list of Inspectors to the user given a GetInspectorsRequest (which is empty)
    public List<Inspector> Get(GetInspectorRequest request)
    {

        InspectorDataWorker pdp = new InspectorDataWorker(Db);
        return pdp.GetInspectorList();
    }

    // Return a single Inspector given their InspectorID
    public Inspector Get(GetInspectorIDRequest request)
    {
        InspectorDataWorker pdp = new InspectorDataWorker(Db);
        return pdp.GetInspectorByID(request.InspectorID);
    }

Thanks for any help!

mark h
  • 19
  • 3

1 Answers1

1

The route http://localhost:50238/Inspector does not match your route definition:

[Route("/InspectorIDRequest/{InspectorID}", Verbs = "GET")]

You can add a new matching route that does, i.e:

[Route("/InspectorIDRequest")]

Or you can modify the existing route to make it a wildcard route that matches both routes i.e:

[Route("/InspectorIDRequest/{InspectorID*}")]

More information on routing is on the Routing wiki.

mythz
  • 141,670
  • 29
  • 246
  • 390
  • Thank you @mythz. Read up on the Wiki as well. Was having a hard time correlating the Routes to Services and then to DataWorker methods. I hope I have better understanding now. For example if I have a current Request – mark h Jun 27 '14 at 03:22
  • Thank you @mythz. Read up on the Wiki as well. Was having a hard time correlating the Routes to Services and then to DataWorker methods. I hope I have better understanding now. For example if I have a current Get Inspector request that returns a List of all Inspectors. Can I add a route that has {FirstName*} in it then include the FirstName property to the request. Then in the Service that currently returns the full list can I alter to call a different Dataworker method if there is a Req param present? Is this best practice or should services be separate? – mark h Jun 27 '14 at 03:29
  • @markh Checkout this previous answer on [designing a Message-Based APIs](http://stackoverflow.com/a/15941229/85785). I recommend splitting out services based on Response type and call semantics, e.g. I would separate services returning multiple vs single results back. Also I'd minimize use of wildcards, they are greedy by design and may match more routes than you wanted to. – mythz Jun 27 '14 at 11:20