Showing posts from November, 2017

Validation in ASP NET Core and Angular

Validation in ASP NET Core and AngularValidation is an important part of any application. There are two parts where validation is required, the API level and the frontend. The API validation is meant to prevent any malformed input to corrupt our data while the frontend validation is meant to guide the user to fill in a form by providing interactive feedback on her input. ASP NET Core for the backend and Angular for the frontend both ship with validation mechanisms fulfilling are requirements. Today we will see how we can implement validation in ASP NET Core using data annotation and inline validation with Angular reactive form. This post will be composed by 2 parts:1. Implement validation for ASP NET Core 2. Implement inline validation for Angular form 1. Implement validation for ASP NET CoreIn ASP NET Core, validation can be implemented using data annotation. On each call, parameters are tested against the annotation and the ModelState property is filled up.
When any of the parameter…

Implement PATCH on ASP NET Core with JSON Patch

Implement PATCH on ASP NET Core with JSON PatchWhen building web APIs, most of the HTTP methods are implemented, GET, POST, PUT, PATCH and DELETE. While GET, POST and PUT are easily implemented, PATCH functionality is slightly different as it allows to change one or more properties of the resource. It is used to patch the resource. One way to do it is to use a protocol called JSON Patch. Today we will see how we can use JSON Patch through the ASP NET Core implementation and how we can construct the request from the frontend. This post will be composed by 3 parts:1. JSON Patch protocol 2. Implementation on ASP NET Core 3. Usage from frontend in TypeScript 1. JSON Patch protocolJSON Patch
is a protocol defining a format expressing operations to be applied on JSON objects.The operations are composed by the following object:{ op: '', path: '', value: '' } op being the operation, path being the path of the property of the JSON object and lastly value being the value…

REST - Representational State Transfer

REST - Representational State TransferSince the past 5 years, there has been an increasing demand to know how to build RESTful Web Services. Never had a job interview for Software Engineering failed to include at least one question about REST or RESTful Web Services and never a week passed with at least hearing one comment like “if we do x, it will not be RESTful”. Everyone seems to be on top of it, know everything about REST.
But is it true? Do they really know REST? How certain can one be that her system is RESTful?
Today I would like to share my point of view about REST by going through three points:1. Overview 2. How does REST link with HTTP protocol 3. What have we learnt 1. OverviewCountless time, I have seen the following:A: Do you know REST? B: Yes A: Can you write the URLs for a REST API for a user profile? B: Ok, there; GET /profiles GET /profiles/123 POST /profiles PUT /profiles/123 PATCH /profiles/123 DELETE /profiles/123 A: Perfect This…

Swagger for ASP NET Core API development

Swagger for ASP NET Core API developmentBuilding a web API is not an easy task. In order to build one easy to use, we need to consider the routes, the HTTP methods, the return results from the endpoints, the parameter used for the body of the requests, etc…
Swagger is a tool which compiles all our API endpoints into a friendly GUI and allows us to directly test them. It brings a lot of benefits as we can easily pinpoint mistakes in the endpoints route or parameters and of course in the implementation since we can straight away call the endpoints.
Today we will see how we can integrate Swagger in 3 parts:1. Add Swagger to ASP NET Core project 2. Handle authentication 3. Handle endpoints specificities with filters 1. Add Swagger to ASP NET Core projectWe start first by creating an empty ASP NET Core project with the following startup:public class Startup { public void ConfigureServices(IServiceCollection services) { services.AddMvc(); } public void Configure(IA…