Azure Web Api Interview Questions And Answers

2 Can we consume Web API 2 in C# console application?

A: Yes, Web API 2 can be consumed in Console Application, MVC, Angular JS, or any other application.

29) How can you restrict access methods to specific HTTP verbs in Web API?

With the help of Attributes (like HTTP verbs), It is possible to implement access restrictions in Web API.

It is possible to define HTTP verbs as an attribute to restrict access.

Example:

8 What do you mean by Internet Media Types?

Formerly known as the MIME type, it refers to the standard design for identifying content on the internet such as the type of information a piece of data contains.

For example, if we receive a file over the email as an attachment, this identifier can be useful in knowing the media type of the attachment information contained in the header so that the browser can launch the appropriate plug-in.

It is a good practice to know information on media types as every internet media type has to comply with the following format –

Each media type must have the ‘type’ and the ‘subtype’ that indicates the type of information it contains. For instance,

– type/png- subtype

Application– type/rss- subtype+xml

6 How can we handle an error using HttpError in Web API?

The HttpError method is used in Web API to throw the response body’s error information. One can also use the “CreateErrorResponse” method along with this one.

1Exception filters in ASP.Net Web API

A: Exception filters in Web API help in implementing IExceptionFilters interface. They perform when an action throws an exception at any point.

4 How parameters get the value in Web API?

A: Parameters get value in Web API in the following way:

1 How can we handle errors in Web API?

A: Handling errors or exceptions in Web API can be done with the help of the following classes –

  • Using HttpResponseException –This exception class helps to return the HTTP status code specified in the exception Constructor.
  • Using HttpError – This exception class helps to return meaningful error code to the client as HttpResponseMessage.
  • Using Exception filters – Exception filters help in catching unhandled exceptions or errors generated in Web API and they can be used whenever the controller action method throws the unhandled error.
  • 18) Can you use Web API with ASP.NET Web Form?

    Yes, It is possible to use Web API with ASP.Net web form. As it is bundled with ASP.NET MVC framework. However, it can be used with ASP.NET Web Form.

    What is the CORS issue in Web API?

    A: CORS is the acronym for Cross-Origin Resource Sharing. CORS solves the same-origin restriction for JavaScript. Same-origin means JavaScript only makes AAJAX call for web pages within the same-origin.

    You have to install the CORS nuget package by using Package Manager Console to enable CORS in Web API.

    Add EnableCors attribute to the Controller class and define the origin.

    [EnableCors(origins: “”, headers: “*”, methods: “*”)].

    6 What are the different HTTP methods used in Web API?

    Though there are a variety of HTTP verbs or methods, the most important and frequently used ones are GET, PUT, POST and DELETE.

    GET – It is used to retrieve information of the resource at a specified URI.

    PUT – The PUT method is used to update the values of a resource at a specified URI.

    POST –POST method is used to create a new request and send data to the respective server.

    DELETE –This method is used to remove the current resource at a specified URI.

    The functionality of these HTTP verbs can be summed up using the acronym CRUD in which each letter corresponds to different action –

    C stands for Create or POST (creating data)

    R stands for Read or GET (data retrieval)

    U stands for Update or PUT (updating data)

    D stands for Delete or DELETE (deleting data)

    Other less frequently used HTTP verbs or methods as per the requirement include –

    HEAD –This method works the same way as the GET method and is primarily used to transfer the header section.

    OPTIONS –This method helps identify and describe the communication option for a specific resource.

    CONNECT –It is used to establish two-way communication between the server and the desired destination with the help of a given URI.

    TRACE – This method is used for diagnostic purposes to invoke a loop-back message along the target path and use that data for testing.

    Top 20 Interview Questions – Web API

    Related Posts

    Leave a Reply

    Your email address will not be published. Required fields are marked *