0% found this document useful (0 votes)
5 views

Webapi

Uploaded by

zxcvbq663
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Webapi

Uploaded by

zxcvbq663
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

It is an application programming interface which works on http protocals

To develop web , mobile and ios applications we can use web api

To avoid duplication of code we will use web api

To provide security , which means webapi will directly intercat with db and acts as
middleware.
Front end applications will not interact directly with the db
Extend app functionality

HTTP VERBS
Status code

status code are recieved from the server and they give info about responses
ex: 101 - its about information response -(An informational response indicates that
the request was received and understood)
200 - success
301 - redirection
404 - error
500 - internal server error

Status codes we will use in asp.net core web api


200(ok) - Success
201 - new resource created
204 - no content(Server processes request but didnt return anything)
301 - redirection
302 - temporary
400- Bad request( sending wrong data )
401 - unauthiorized(resource dont have access to the application)
404 - not found
405 - method error(other than HTTP verbs)
Action return types

Iactionresult
Custom return types

web api versioning


-
As developers, we often add new features to our apps and modify current APIs as
well. Versioning enables us to safely add new functionality without breaking
changes
Install-Package Microsoft.AspNetCore.Mvc.Versioning
services.AddApiVersioning();
services.AddApiVersioning(config =>
{
config.DefaultApiVersion = new ApiVersion(1, 0);
config.AssumeDefaultVersionWhenUnspecified = true;
});
[ApiVersion("1.0")]
we want to create a different version of an existing Student Information service.
Now, to consume the latest version, the client must pass the version information
along with the query string.
If they do not pass any value in the query then by default Version 1 will execute.

If they specify Version 1 in the query string then it will execute Version 1 and if
they specify Version 2 then as expected Version 2 will execute.
ihostbuilder and webhost
middleware

What is the use of IConfiguration?


The IConfiguration interface is used to read Settings and Connection Strings from
AppSettings. json file.
You will need to import the following namespace.
IEnumerable interface -- to use array of string list ....

web api versioning


Global Exception pratical
ihostbuilder ad iwebhostbuilder
ilogger or serilog and save it ito .json file

--------------------------------LOGGING AND TYPES------------------------

what is logging?
It is the process of storing logs
Microsoft.extensions.logging
logging api and logging providers
logging providers two types
1. Built in
console,debug,eventsource,eventlog
2.Third Party
serilog,log4net,nlog,stcak driver
Iloggerfactory extension methods

Serilog conepts

-- loglevel
Trace (0),Debug(1),Information(2),warning(3),error(4),critical(5), none(6)

You might also like