1

I'm trying to implement a specific HTTP interface (SAP Content Server HTTP Interface) with .NET Standard WebAPI, that requires that the routes be all in the form of:

http://server:port/somepath/controller?action&parameter1=value1&parameter2=value2...

Example:

GET

http://www.google.com/myapi/api?getStuff&stuffId=1&otherParameter=2

POST,PUT

http://www.google.com/myapi/api?putStuff&stuffId=1&otherParameter=2

Is it at all possible to do this specific routing with the action after the question mark and parameters afterwards ?

Interface specification: https://help.sap.com/doc/b743f868cdf249cfb829a5a121cc9436/7.0/en-US/SAPHTTPInterfaceOct.pdf

7
  • I would recommend this being more RESTful: GET/PUT/POST/DELETE http://server:port/somepath/{controller}/{id}?{parameter1}={value1}&{parameter2}={value2}... Commented Jan 23, 2020 at 16:13
  • Does this answer your question? How do I access URL parameters in web API? Commented Jan 23, 2020 at 16:14
  • Is there a particular reason you want the action to be a query parameter and not part of the path? While you can change the route Template to achieve this, it's a pretty non-standard pattern that will make your life harder. Commented Jan 23, 2020 at 16:43
  • I have to conform to a standard protocol in order to integrate with SAP ArchiveLink help.sap.com/doc/b743f868cdf249cfb829a5a121cc9436/7.0/en-US/… If not, I would be doing this the most usual way, as I know this is pretty non-standard. Commented Jan 23, 2020 at 16:59
  • 1
    I played around with a sample project and it seems that you cannot actually have a "?" in the routeTemplate. It's not allowed by default. I think if your action is a query parameter, then you are going to have to do some sort of custom implementation of the IHttpActionSelector interface and write your own code to select the correct action based on the first query parameter. Commented Jan 23, 2020 at 17:40

2 Answers 2

0

This should be possible by mapping your routes:

routes.MapHttpRoute(
    name: "ActionApi",
    routeTemplate: "api/{controller}?{action}&{id}&{parameter1}",
    defaults: new { id = RouteParameter.Optional }
);

The query parameters can be added to your controller action:

public HttpResponseMessage Get(int id, string parameter)
{
   //...
}
Sign up to request clarification or add additional context in comments.

Comments

0

I ended up using url rewrite module in iis to transform the requests before reaching the api:

 <rewrite>
    <rules>
      <rule name="convert requests">
        <match url="^api/sapcs" />
        <action type="Rewrite" url="/api/sapcs/{C:1}?{C:2}" appendQueryString="false" />
        <conditions>
          <add input="{QUERY_STRING}" pattern="([^&amp;]+)&amp;(.*)" />
        </conditions>
      </rule>
    </rules>
  </rewrite>

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.