Web API

 URI - it can be of type http, FTP or mailto.

In Web API - all are resource 

I guess unlike web service, in web api , we dont create proxy class 


First - we need URL

second - what types of methods

third - what type of data


URI will be same but based on method type [GET or Delete ] the action will be invoked inisde API.

services.AddDBContext<OrganizationContext> --->inside Configservice class is add like dependency injection way. Reason is since there are lot of controllers then we create in each and every controller OrganizationContext object which is very time consuming process. that's why if we added in Configservice then Dependency injection will take care of creating the OrganizationContext object in each and every controller and pass it to the controller constrcutor and it will also take care of disposing the object also.


Swagger  - It is for those who are consuming our developed services

Fiddler - It is used for developers to test the scenarios

Since we are working on API, 

GET --->we need to tell the status code of API response. That is ok--->200 and notfound --->404 etc. 

POST-->if the record is inserted/created successfully then we need to use CreatedAtAction(), If there is certain implemented and if that validation fails or if the data passed is invalid then we need to use BadRequest().

CreatedAtAction() --> This will return the created object with URI to access the created object (Location )

Model state --> will have all the errors added into it

500 --->it is for unhandled exception in code

204--->No content returned. This is best for Update and Delete


What is AsNoTracking?

AsNoTracking(IQueryable) Returns a new query where the entities returned will not be cached in the DbContext or ObjectContext. This method works by calling the AsNoTracking method of the underlying query object.

use of async and await in web api helps in improving the response time when millions of users access the web api and also in load testing 


Bear in mind that the primary benefit of asynchronous code on the server side is scalability. It won't magically make your requests run faster. I cover several "should I use async" considerations in my article on async ASP.NET.

I think your use case (calling other APIs) is well-suited for asynchronous code, just bear in mind that "asynchronous" does not mean "faster". The best approach is to first make your UI responsive and asynchronous; this will make your app feel faster even if it's slightly slower.

converting your object from one form to another form is called Serialization. Example converting your employee object into XML format is called XML Serialization.

converting your employee object into byte 0 and 1 format is called Binary Serialization.

converting your employee object into Json format is called Json Serialization.


converting your Json into CLR object format is called Json DeSerialization.

So when ever we are working with API then there will be always Serialization and DeSerialization


POST and PUT --->DeSerialization

eager loading

Circular referencing --> Here the object will be linked to another object details. It is like chain link. It keeps going on and sometimes no end.

Here OK method is performing serialization [i mean converting object from one form to another form. Here converting object to json]. To do this we need one package called newtonsoft.json using which we can tell the code to ignore circular reference issues

Why do we need Asynchronous Action method in WEB API

=================================================

This article explains the Asynchronous Action method and how to create it in the Web API. The purpose of this is to create the asynchronous method for handling more than one request on the same number of thread pools. The thread pool is maintained by the .Net framework on the IIS server. There is a finite number of threads available in the thread pool.

When any request arrives the request is assigned to the process by the thread of the thread pool. This thread basically works as the request is processed, and after completing one request the thread is returned back to the pool to service another request. An asynchronous method allows you to start a long-running operation, returns your thread to the pool, and wakes up on a different thread or the same depending on the availability of threads in the pool at that time.


https://www.c-sharpcorner.com/UploadFile/2b481f/create-asynchronous-action-method-in-web-api/







Comments

Popular posts from this blog

Understanding Collection and Object Initializer

How to execute Javascript in VS code