The project introduces a method that processes JTokens in order to return only the properties requested by the client.
- Usage
- Example in API Controller
var _tracksVM = Mapper.Map<IEnumerable<Track>, IEnumerable<TrackViewModel>>(_tracks);
string _serializedTracks = JsonConvert.SerializeObject(_tracksVM, Formatting.None,
new JsonSerializerSettings()
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
});
JToken _jtoken = JToken.Parse(_serializedTracks);
if (!string.IsNullOrEmpty(props))
Utils.FilterProperties(_jtoken, props.ToLower().Split(',').ToList());
return Ok(_jtoken);
<p>
The project is built in Visual Studio 2015 and ASP.NET Core but the technique and the method can be easily integrated in any version of ASP.NET API. In case you want to run the <i>ShapingAPI</i> application:
<ol>
<li>
Download the source code and open the solution in Visual Studio 2015
</li>
<li>
Restore Nuget and Bower packages
</li>
<li>
Install the <a href="https://chinookdatabase.codeplex.com/" target="_blank">Chinook</a> database in your SQL Server by running the script inside the <a href="https://github.com/chsakell/multi-client-api/tree/master/src/ShapingAPI/SQL" target="_blank">SQL</a> folder.
</li>
<li>
Alter the <i>appsettings.json</i> file to reflect your database environment.
</li>
<li>
Run the application
</li>
</ol>
</p>
<h3 style="font-weight:normal;">Follow chsakell's Blog</h3>
<table id="gradient-style" style="box-shadow:3px -2px 10px #1F394C;font-size:12px;margin:15px;width:290px;text-align:left;border-collapse:collapse;" summary="">
<thead>
<tr>
<th style="width:130px;font-size:13px;font-weight:bold;padding:8px;background:#1F1F1F repeat-x;border-top:2px solid #d3ddff;border-bottom:1px solid #fff;color:#E0E0E0;" align="center" scope="col">Facebook</th>
<th style="font-size:13px;font-weight:bold;padding:8px;background:#1F1F1F repeat-x;border-top:2px solid #d3ddff;border-bottom:1px solid #fff;color:#E0E0E0;" align="center" scope="col">Twitter</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="4" style="text-align:center;">Microsoft Web Application Development</td>
</tr>
</tfoot>
<tbody>
<tr>
<td style="padding:8px;border-bottom:1px solid #fff;color:#FFA500;border-top:1px solid #fff;background:#1F394C repeat-x;">
<a href="https://www.facebook.com/chsakells.blog" target="_blank"><img src="https://chsakell.files.wordpress.com/2015/08/facebook.png?w=120&h=120&crop=1" alt="facebook" width="120" height="120" class="alignnone size-opti-archive wp-image-3578"></a>
</td>
<td style="padding:8px;border-bottom:1px solid #fff;color:#FFA500;border-top:1px solid #fff;background:#1F394C repeat-x;">
<a href="https://twitter.com/chsakellsBlog" target="_blank"><img src="https://chsakell.files.wordpress.com/2015/08/twitter-small.png?w=120&h=120&crop=1" alt="twitter-small" width="120" height="120" class="alignnone size-opti-archive wp-image-3583"></a>
</td>
</tr>
</tbody>
</table>