Is this a good way to handle Web API UriTemplates?
There is an easier way. You can use uri templates to help you by making both handling methods operations.

[ServiceContract]
public class ContactsApi
{
    [WebGet(UriTemplate="{id}")]
    public string GetById(int id)
    {
        //return by id
    }

    [WebGet(UriTemplate="{first} {last}")]
    public string GetByName(string first, string last)
    {
        //return by name
    }
}


If you do a GET on /contacts/Matt%20Phillips the second method will get invoked.