0

Based on the code below, I'm able to call /api/cards and /api/cards/list but now /api/cards/1234567890

WebApiConfig

config.Routes.MapHttpRoute( _
       name:="WithActionAndIdApi", _
       routeTemplate:="api/{controller}/{action}/{id}", _
       defaults:=New With {.id = RouteParameter.Optional} _
   )

    config.Routes.MapHttpRoute( _
        name:="WithIdApi", _
        routeTemplate:="api/{controller}/{id}" _
    )

    config.Routes.MapHttpRoute( _
        name:="DefaultApi", _
        routeTemplate:="api/{controller}", _
        defaults:=New With {.action = "DefaultAction"} _
    )

CardsController

<HttpPost()>
<ActionName("DefaultAction")>
Public Function PostValue(<FromBody()> ByVal value As Card_POST.Card) As HttpResponseMessage

<HttpPost()>
<ActionName("list")>
Public Function PostValue(<FromBody()> ByVal value As Cards_POST.CardList) As HttpResponseMessage

<HttpPut()>
Public Function PutValue(ByVal Id As String, <FromBody()> ByVal value As Card_PUT) As HttpResponseMessage
4
  • please make sure you are asking a question. It is unclear what problem you are having or what you are attempting to solve. Commented Jan 10, 2017 at 13:19
  • How you do the PUT request? Commented Jan 13, 2017 at 0:25
  • @Mate, I've solved the issue by changing my config.Routes Commented Jan 13, 2017 at 1:42
  • Great! Congratulations! Mark as correct your own answer Commented Jan 13, 2017 at 2:06

1 Answer 1

1

I've changed my config.Routes into below code and it is able to support my situation above.

config.Routes.MapHttpRoute( _
       name:="DefaultApiWithId", _
       routeTemplate:="api/{controller}/{id}", _
       defaults:=New With {.id = RouteParameter.Optional}, _
       constraints:=New With {.id = "^\d+$"} _
    )

    config.Routes.MapHttpRoute( _
       name:="DefaultApiWithAction", _
       routeTemplate:="api/{controller}/{action}" _
   )

    config.Routes.MapHttpRoute( _
       name:="DefaultApiGet", _
       routeTemplate:="api/{controller}/{id}", _
       defaults:=New With {.id = RouteParameter.Optional}, _
       constraints:=New With {.httpMethod = New HttpMethodConstraint({"GET"})} _
   )

    config.Routes.MapHttpRoute( _
       name:="DefaultApiPost", _
       routeTemplate:="api/{controller}", _
       defaults:=New With {.action = "DefaultPostAction"}, _
       constraints:=New With {.httpMethod = New HttpMethodConstraint({"POST"})} _
   )

    config.Routes.MapHttpRoute( _
       name:="DefaultApiPut", _
       routeTemplate:="api/{controller}/{id}", _
       defaults:=Nothing, _
       constraints:=New With {.httpMethod = New HttpMethodConstraint({"PUT"})} _
   )
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.