Skip to main content

Posts

A simple ASP.Net Core Web API with a Simple Service

Project description The API provides a functionality to create and read a value from the server. Purpose of the project is to demonstrate how the values can be persisted in the server memory using singleton objects.
POST method creates a value in the serverGET method reads boack the value from the server Sourcode The complete source code of the project can be found in GitHub at https://github.com/sureshatt/aspdotnetcore-proj/tree/master/APIWithService
Running the project Run the project in Visual Studio.
The application will start in port 65387 due the configuration in the Program.cs file.
Consuming APIs
Use the postman collection in the project https://github.com/sureshatt/aspdotnetcore-proj/blob/master/APIWithService/APIWithService.postman_collection.json
Analysis Startup.cs In the Startup.cs the service.AddSingleton() method is used to inject the MyTyle singleton object.
IMyType.cs Is the type which defines the mecahanism to store and read value from the server meomey.
MyType.cs Im…
Recent posts

Simple REST API with ASP.Net Core 1.1

Project Description This is a simple REST API which manages a static list of names. Each name in the list can be identified by their index of the list.  GET method returns the complete list of namesGET(id) method returns the name at the provided index of the listPOST method adds a new name to the list and returns the updated list of names.PUT(id) method updates/replace a name at the given index of the listDELETE(id) method deletes the name at the given index of the list Sourcecode  The complete source code of the project can be found in GitHub at https://github.com/sureshatt/aspdotnetcore-proj/tree/master/static_names_list_api_project
Running the project Run the project in Visual Studio.
The application will start in port 65387 due the configuration in the Program.cs file.
Consuming APIs Use the postman collection in the project https://github.com/sureshatt/aspdotnetcore-proj/blob/master/static_names_list_api_project/StaticNamesListAPI.postman_collection.json to consume the APIs.
Anal…

ASP.NET WEB API template of Visual Studio

Here I will be using ASP.Net Core 1.1 and the ASP.NET Core Web API project template of Visual Studio (for Mac)
Creating the project with templates The ASP.NET Core Web API template can be found under .Net Core menu.

Once a project is created with the template, there are two important class files (.cs) being created.
Startup.csValuesController.cs  Startup.cs
There are two things done in the Startup.cs: The MVC framework is configured for dependency injection using the addMvc() method in the ConfigureService method. The MVC framework middlware is also configured in the middleware pipeline using the UseMvc() method in the Configure method.  ValuesController The Route The route is defined using the "Route" annotation. This will define how the controller can be reached using HTTP (The URL)
The method [HttpGet],[HttpPost],[HttpPut],[HttpDelete] annotations are used to define the http verbs against the methods. 
ConclusionTo build Rest APIs, it is required to add the MVC framework de…

Getting started with ASP.Net Core

Being a Java EE developer for many years I was wondering how I can start with the .Net stack, specially in the web development. Coincidentally this is a very good era to start with .Net as now the .Net framework is now open sourcecross-platform and in new versions (.Net Core and ASP.Net Core). Further, the favorite .Net IDE, Visual Studio is too now available for Mac. Therefore this is the perfect combination to start web development in .Net. Let us have a look how to create a simple ASP.Net "Hello World" application with ASP.Net in Mac.
Prerequisites Step 1: Install .Net framework in Mac The steps defined here https://www.microsoft.com/net/core#macos are clean and perfect. It just works.
Step 2: Install Visaul Studio for Mac Download and install from here https://www.visualstudio.com/vs/visual-studio-mac/.
Creating first ASP.Net Core project with Visual Studio Step 1: When Visual Studio is launched, following welcome screen will be shown. Select "New project" fr…

Understanding Assembly basic syntax

Here is a simple C program,

int main() {
   return 0;
}

Now let us generate the Assembly code for this,

gcc -S mycode.c

The output is given bellow,

.section__TEXT,__text,regular,pure_instructions
.macosx_version_min 10, 12
.globl_main
.align4, 0x90
_main:  ## @main
.cfi_startproc
## BB#0:
pushq%rbp
Ltmp0:
.cfi_def_cfa_offset 16
Ltmp1:
.cfi_offset %rbp, -16
movq%rsp, %rbp
Ltmp2:
.cfi_def_cfa_register %rbp
xorl%eax, %eax
movl$0, -4(%rbp)
popq%rbp
retq
.cfi_endproc


.subsections_via_symbols

Varius parts of the code are colored in different colors for better understanding:

In green are various directives which will not be discussed in the blog.In red are various labels which are not executable commonds.In blue are the comments. In black are the real assembly commands. 

So the code real assembly code is,

pushq%rbp
movq%rsp, %rbp
xorl%eax, %eax
movl$0, -4(%rbp)
popq%rbp
retq

Opcode and Operand Blue and Green are Opcodes (which specify which operation to perform)
Red and Purpul are Operands (which specify data for the o…

Disassembling executable program with objdump in Ubuntu

objdump tool can be used to disassble an executable program to the assembly code.


objdump -d a.out
The resulting code would be for example:


Generating Assembly code out of C program with GCC

It is pretty straight forward to generate the assembly code out of the C program using GCC.

C program int main() { 
 int x = 1; 
 return x; 
}


Now GCC -S switch can be used to just to genrate the assembly code
gcc -S mycode.c 

The Assembly code would be store in the file mycode.s.

Assembly code
        .file   "int3.c"
        .text
        .globl  main
        .type   main, @function
main:
.LFB0:
        .cfi_startproc
        pushq   %rbp
        .cfi_def_cfa_offset 16
        .cfi_offset 6, -16
        movq    %rsp, %rbp
        .cfi_def_cfa_register 6
        movl    $1, -4(%rbp)
        movl    -4(%rbp), %eax
        popq    %rbp
        .cfi_def_cfa 7, 8
        ret
        .cfi_endproc
.LFE0:
        .size   main, .-main
        .ident  "GCC: (Ubuntu 5.4.0-6ubuntu1~16.04.2) 5.4.0 20160609"
        .section        .note.GNU-stack,"",@progbits