Send JSON in http Get with angular and Web Api

Requirement: Need to send complex in http get request using Angular and get the JSON in Web API

First prepare URLSearchParams object and add key value pairs.
Send the RequestOptions to Angular http service.

final url format will be
{{API-URL}}/api/folders/370/documents?filter={ 'startDate':'08/01/2005', 'endDate':'08/31/2005','currentPage': '2', 'pageLimit': '50'}

On the API Side
Got the query parameter and deserialize to ViewModel
Your server side ViewModel matches your JSON object sent in the request.

var filterData = Request.GetQueryNameValuePairs();
if (filterData == null || !filterData.Any())
throw new ArgumentException("Invalid request: search parameters are missing.");
var viewModel = JsonConvert.DeserializeObjectfilterData.First().Value);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s