0

I have a method which conducts a search based on 3 criteria:

  • Author
  • Title
  • Keywords

The API method I have created for this search currently looks like this:

[Route("A={author};T={title};K={keywords}")]
[ResponseType(typeof(bool))]
public HttpResponseMessage Get(string author, string title, string keywords)
{            
    //Code for search
}

The method works perfectly fine when all 3 parameters are passed. However, if I were to simply just enter an author and not title or keywords, I receive a Not Found error.

Is there a way I can modify the route to allow for when 1 or more parameters are null/empty strings?

0

1 Answer 1

0

Any parameters not mentioned in the Route string will be mapped when sent as part of the query string of the URL. For example:

http://www.yourapi.com/path/to/endpoint?author=DouglasAdams&keywords=Hitchhiker

will call your method with author = "DouglasAdams", title = null, and keywords = "Hitchhiker" if you use Route("path/to/endpoint").

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.