Skip to content
This repository was archived by the owner on Apr 18, 2020. It is now read-only.

Web API Route

Jaime Still edited this page Sep 9, 2016 · 1 revision

For detailed information on Web API, see Building Web APIs with ASP.NET.

Here, we are defining an HTTP Request that an Angular Service can call and pass data to / retrieve data from in order to execute the desired PowerShell script.

I prefer to use Route Attributes to define the URL that the HTTP Request can be reached. The HttpMethod is also specified, indicating the type of HTTP Request that the route corresponds to. Since I am sending a JSON object in the body of the request, this will be an HttpPost method.

The signature of the actual method should emulate the details of the extension method that was created to execute the PowerShell script. It returns an IEnumerable<ResultModel> and receives an instance of QueryWmiModel. Given all of the above information, the Web API method that is used to execute the query-wmi.ps1 script is as follows:

[Route("api/wmi/queryWmi")]
[HttpPost]
public async Task<IEnumerable<ResultModel>> QueryWmi(QueryWmiModel model)
{
    return await model.QueryWmi();
}
Clone this wiki locally