Mapping parameters #82
-
Are there any examples of mapping path parameters? I've done this but it didn't work. Are there any other things I have to set up? [RestRoute("Get", "/api/heartbeat/{requestID}")]
public async Task Heartbeat(IHttpContext context)
{
var requestID = context.Request.PathParameters["requestID"];
await context.Response.SendResponseAsync(requestID).ConfigureAwait(false);
} I'm using the path and query string |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Path parameters are different from the query string. If you want the request id in the path parameter, your path should be [RestRoute("Get", "/api/heartbeat/{requestID}")]
public async Task Heartbeat(IHttpContext context)
{
var requestID = context.Request.PathParameters["requestID"];
await context.Response.SendResponseAsync(requestID).ConfigureAwait(false);
} If you want the request id to be in the query string, you would use your existing path and query string of [RestRoute("Get", "/api/heartbeat")]
public async Task Heartbeat(IHttpContext context)
{
var requestID = context.Request.QueryString["requestID"];
await context.Response.SendResponseAsync(requestID).ConfigureAwait(false);
} You don't want to include the query string in the path pattern. |
Beta Was this translation helpful? Give feedback.
Path parameters are different from the query string.
If you want the request id in the path parameter, your path should be
/api/heartbeat/ab123
, and you would use the your existing method, with a modification to theRoute
attribute:If you want the request id to be in the query string, you would use your existing path and query string of
/api/heartbeat?requestID=ab123
, but yourRoute
attribute and method would change to: