Posts

Showing posts with the label Web API

REST - Representational State Transfer

REST - Representational State Transfer Since 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. Overview Countless 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: P...

Swagger for ASP NET Core API development

Image
Swagger for ASP NET Core API development Building 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 project We 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 Co...

Create a simple Microsoft Orleans application

Create a simple Microsoft Orleans application Last week I presented an overview of Microsoft Orleans . Gave an explanation on the concepts and keywords which can be found in the framework. Today I will explain how we can implement a simple Orleans application with a cluster composed by a localhost Silo and with a client within an ASP Net Core Mvc application. This post will be composed by 3 parts: 1. Implement the grains 2. Create the silo 3. ASP Net Core Mvc client 1. Implement the grains The grains are the unit of work in an Orleans application. They contain the business logic and ensure that the state is consistent. In our example we will be implementing a Bank account grain with a withdraw and deposit functionality. There will be a single business rule being that the balance of any account cannot be lower than 0. We start first by creating the grain interface in a project where we reference Orleans.Core . public interface IBankAccount: IGrainWithStringKey { Task Deposi...

A better dotnet CLI experience with ConEmu

Image
A better dotnet CLI experience with ConEmu When developing multiple Web api under multiple Visual Studio solutions, it can become very tedious to maintain, run and debug. Opening multiple instances of Visual Studio is very costly in term of memory and running all at once also clutter the screen which rapidly becomes irritating. With the advent of dotnet CLI tools, it has been clear that the next step would be to move out of the common “right click/build, F5” of Visual Studio and toward “dotnet run” on a command prompt. Last month I was looking for a Windows alternative of the bash terminal which can be found on Mac and I found ConEmu . ConEmu provides access to all typical shells via an enhanced UI. It is actively maintained and open sourced https://github.com/Maximus5/ConEmu . Today we will see how we can use ConEmu to ease our development process by leveraging only 2 of its features; the tasks and environment setup. This post will be composed by 4 parts: 1. dotnet CLI 2. Setup ...

Configurations in ASP NET Core

Configurations in ASP NET Core Every application needs configurations, whether it is a port, or a path or simply string values. In order to deal with configurations, ASP NET Core ships with a Configuration framework. The framework provides a builder allowing to read configurations from different json files, supports environment convention and also defining custom configuration providers in order to read from other sources like MSSQL or other services. Today we will see how we can use the configuration framework. This post will be composed by 2 parts: 1. Install the configuration framework 2. Make configuration injectable via Options 1. Install the configuration framework We start first by making sure we have the library installed, Microsoft.Extensions.Configuration . In Startup constructor use the ConfigurationBuilder to extract configurations: public IConfigurationRoot Configuration { get; set; } public Startup(IHostingEnvironment env) { var builder = new ConfigurationBu...