Showing posts with label API Attribute. Show all posts
Showing posts with label API Attribute. Show all posts

Sunday 5 March 2023

Common attributes you can use to configure an API in .NET

API stands for Application Programming Interface. It is a set of protocols, routines, and tools that allow various software applications to communicate with each other. APIs are often used to enable integration between different systems, allowing them to share data and functionality with each other.

Below are some common attributes you can use to configure an API in .NET:
  • [HttpGet]: Specifies that a controller method should handle HTTP GET requests.
  • [HttpPost]: Specifies that a controller method should handle HTTP POST requests.
  • [HttpPut]: Specifies that a controller method should handle HTTP PUT requests.
  • [HttpDelete]: Specifies that a controller method should handle HTTP DELETE requests.
  • [AllowAnonymous]: Allows unauthenticated access to a controller or action method.
  • [Authorize]: Restricts access to a controller or action method to authenticated users.
  • [Route]: Specifies the URL pattern for a controller or action method.
  • [FromBody]: Specifies that a parameter should be bound from the request body.
  • [FromQuery]: Specifies that a parameter should be bound from the query string.
  • [ProducesResponseType]: Specifies the expected HTTP response type for a controller or action method.
  • [Produces]: Specifies the expected content types for a controller or action method.
  • [ProducesResponseType(StatusCodes.Status404NotFound)]: Specifies that a method returns a 404 Not Found status code in case the resource is not found.
  • [ProducesResponseType(StatusCodes.Status500InternalServerError)]: Specifies that a method returns a 500 Internal Server Error status code in case of an unhandled exception.