> For the complete documentation index, see [llms.txt](https://admincode.gitbook.io/admincode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://admincode.gitbook.io/admincode/basics/apis-and-integrations/exposing-a-rest-controller.md).

# Exposing a REST controller

A **REST Controller** is a component in web development used to handle RESTful web service requests. It provides endpoints to interact with the server using HTTP methods such as GET, POST, PUT, and DELETE, allowing CRUD operations. Here's a concise explanation with an example concept:

* **GET**: Retrieve data from the server.
* **POST**: Send new data to the server.
* **PUT**: Update existing data on the server.
* **DELETE**: Remove data from the server.

In a REST Controller, endpoints are typically defined for each of these operations, enabling clients to perform CRUD operations on resources. Below is a simple conceptual outline of REST endpoint definitions:

```plaintext
GET /resources - List all resources.
GET /resources/{id} - Retrieve a specific resource by ID.
POST /resources - Create a new resource.
PUT /resources/{id} - Update a specific resource by ID.
DELETE /resources/{id} - Delete a specific resource by ID.
```

REST Controllers are commonly implemented in web frameworks that support RESTful services, such as Spring Boot in Java,

**example ArticleApi Controller with**[ **bearer token authentication**](https://admincode.gitbook.io/admincode/basics/apis-and-integrations/rest-api-authentication.md)

```java
package com.rce.webapi;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.rce.dto.ArticleDTO;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.*;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;

@RestController
@SecurityRequirement(name = "Bearer Authentication")
@Tag(name = "Articles", description = "The Articles API. Contains all the operations that can be performed on an Article.")
@RequestMapping("/api/v1/article")
public class ArticleApiController extends BaseApiController {

    @Operation(summary = "Get an article by its id")
    @ApiResponses(value = { 
      @ApiResponse(responseCode = "200", description = "Found the Article", 
        content = { @Content(mediaType = "application/json", 
          schema = @Schema(implementation = ArticleDTO.class)) }),
      @ApiResponse(responseCode = "400", description = "Invalid id supplied", 
        content = @Content), 
      @ApiResponse(responseCode = "404", description = "Article not found", 
        content = @Content) })
    @GetMapping("/{id}")
    public ArticleDTO findById(@PathVariable(value = "id") long id) throws Exception {	
        return (ArticleDTO) Facade.load(id, ArticleDTO.class);
    }
}
```
