Building the ASP.NET API app

Basics taken from the video: "Building Secure Web APIs with ASP.NET Core"
https://www.youtube.com/watch?v=2PRy38vK5VM

Setting Up a .NET Core Server With Entity Framework Core Using a PostgreSQL Database

https://medium.com/@mikezrimsek/setting-up-a-net-core-server-with-entity-framework-core-using-a-postgresql-database-242438f7d9c3#.w99tdd5yz

Using Swagger UI

Swagger UI is a framework for testing RESTful API.

From the source video: Installing and using Swagger

In `Startup.cs` add:

        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddMvc();
 
            // !!! ADD THOSE LINES:
            services.AddSwaggerGen();
        }
 
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();
 
            app.UseMvc();
 
            // !!! ADD THOSE LINES:
            app.UseSwaggerGen();
            app.UseSwaggerUi();
        }

In order to test it go to:
http://localhost:64479/swagger/ui/index.html

(for me it didn't work without the `index.html`)

Authorization

From the source video: Authorization part.

If we don't want to use Azure or Gmail accounts, we'll have to use OpenIdDict (github project for Core here) to provide the tokens.

Blog: "Setting up ASP.NET v5 (vNext) to use JWT tokens (using OpenIddict)":
http://capesean.co.za/blog/asp-net-5-jwt-tokens/

…and this is the complete code from the tutorial:
https://github.com/capesean/openiddict-test

Dapper micro-ORM

Video: "ASP.NET MVC - Dapper, Areas, and Layouts"
https://www.youtube.com/watch?v=G6o9ilh6uBY

Blog: "Use Dapper.NET ORM in ASP.NET MVC"
http://venkatbaggu.com/use-dapper-net-orm-in-asp-net-mvc/

As for today, the MySQL connector for .Net Core is not ready yet. Available options are either PostgreSQL or SQLite.
http://stackoverflow.com/questions/28321636/asp-net-5-mvc-6-with-mysql-database

Microsoft's Internal REST API Design Guidelines

https://github.com/Microsoft/api-guidelines/blob/master/Guidelines.md

PostgreSQL

Tutorials

Installation on Windows (set speed at x2):
https://www.youtube.com/watch?v=1GlQpflJZTU

How To Create A Postgres Database Using pgAdmin (from Postgres official channel):
https://www.youtube.com/watch?v=1wvDVBjNDys

Change PostgreSQL errors from French to English

Source: http://stackoverflow.com/a/36185134/831138

Change this part of the file "postgresql.conf" (in my case it was under "C:\Program Files\PostgreSQL\9.5\data\postgresql.conf"), and then restart the server (Services -> postgresql-x64-9.5 -> Restart):

# These settings are initialized by initdb, but they can be changed.
lc_messages = 'English_United States.1252'  # locale for system error message

# strings
lc_monetary = 'English_United States.1252'  # locale for monetary formatting
lc_numeric = 'English_United States.1252'   # locale for number formatting
lc_time = 'English_United States.1252'      # locale for time formatting

# default configuration for text search
default_text_search_config = 'pg_catalog.english'

Arguments for PostgreSQL » MySQL

(from the Postgres wiki) Why do you want to migrate?

There are different reasons why a user wants to migrate. Mostly for migrations from MySQL to PostgreSQL it is one of the following:

  • performance reasons
  • stableness
  • reliability
  • GIS
  • Replication issues
  • Cluster issues
  • High availability issues
  • localisation/globalisation issues
  • need of object relational features
  • sick of bugs
  • costs for license (dual license, GPL)
  • license (BSD instead of GPL)

Ten Reasons Why You Should Prefer PostgreSQL to MySQL:
http://www.slideshare.net/anandology/ten-reasons-to-prefer-postgresql-to-mysql

What PostgreSQL has over other open source SQL databases:
"If you do anything with spatial data, PostgreSQL with PostGIS is the way to go."
https://www.reddit.com/r/programming/comments/3plq65/what_postgresql_has_over_other_open_source_sql/

Technical comparison between both:
https://www.wikivs.com/wiki/MySQL_vs_PostgreSQL

Video: "PostgreSQL vs. MySQL - Pros & Cons"
https://www.youtube.com/watch?v=yCpu3IDdy6M

Migrating MySQL to PostgreSQL

Video: "Large Scale MySQL Migration to PostgreSQL"
https://www.youtube.com/watch?v=7PlbCbiCFng

Info taken from the PostgreSQL wiki.

Using the Migration Toolkit (from EntrepriseDb)

Free tool:
http://www.enterprisedb.com/downloads/postgres-postgresql-downloads

Extract the files from the zip and fun the installer (`ppasmeta-9.5.0.5-windows-x64.exe`) as administrator.

To enable MySQL connectivity, download MySQL's freely available JDBC driver from:
http://www.enterprisedb.com/downloads/third-party-jdbc-drivers

Place the `mysql-connector-java-5.0.8-bin.jar` file in the "JAVA_HOME\jre\lib\ext" directory (in my case: "C:\Program Files\Java\jre1.8.0_60\lib\ext\mysql-connector-java-5.0.8-bin.jar").

The Migration Toolkit documentation can be found here (online doc) or here (pdf version).

First: modify `C:\Program Files\PostgresPlus\edbmtk\etc\toolkit.properties` (Info):

SRC_DB_URL=jdbc:mysql://SOURCE-HOST-NAME/SOURCE-DB-NAME
SRC_DB_USER=********
SRC_DB_PASSWORD=********

TARGET_DB_URL=jdbc:edb://localhost:5444/DESTINATION-DB-NAME
TARGET_DB_USER=enterprisedb
TARGET_DB_PASSWORD=********

Then: execute `C:\Program Files\PostgresPlus\edbmtk\bin\runMTK.bat` (Info).

runMTK.bat -sourcedbtype mysql -targetdbtype enterprisedb -allTables YOUR_DB_SCHEMA

// ...or with a limited subset of tables:

runMTK.bat -sourcedbtype mysql -targetdbtype enterprisedb -tables TABLE1,TABLE2,TABLE3 YOUR_DB_SCHEMA

In order to get this subset of tables from MySQL:

SELECT 
    GROUP_CONCAT(TABLE_NAME)
FROM
    information_schema.tables
WHERE
    TABLE_SCHEMA = 'your_db_name'

For further problems, read my own StackOverflow post here.

API deployment

Video: "Deploying ASP.NET Core Applications"
https://www.youtube.com/watch?v=7TERFQ_U9W0

Want to learn more about Docker? Take the "hands on" course at https://www.katacoda.com/ .

Pending links

Introduction to Dependency Injection in ASP.NET Core
https://www.youtube.com/watch?v=N11urCXU3IQ

ASP.NET Core ASP.Net 5 Tutorial for Beginners
https://www.youtube.com/watch?v=SCCB074j0gs

Z2P C# ASP.NET MVC - Dapper, Areas, and Layouts
https://www.youtube.com/watch?v=G6o9ilh6uBY

RabbitMQ is open source message broker software (sometimes called message-oriented middleware) that implements the Advanced Message Queuing Protocol (AMQP).
https://www.rabbitmq.com/tutorials/tutorial-one-dotnet.html

Comments

Becoming a Wikidot member is free and easy: create an account.

You have to be a Wikidot member to add comments to a Wikidot blog.

Add a New Comment