restclient-migration
БесплатноБез исполняемых скриптовНе проверенMigrate RestTemplate to RestClient in Spring Boot 3.2+. Use when replacing deprecated RestTemplate with modern fluent API, updating HTTP client code, or…
от benchflow-ai★ 1 941 звезда на GitHubОб этом скилле
RestTemplate to RestClient Migration Skill
Overview
Spring Framework 6.1 (Spring Boot 3.2+) introduces RestClient, a modern, fluent API for synchronous HTTP requests that replaces the older RestTemplate. While RestTemplate still works, RestClient is the recommended approach for new code.
Key Differences
| Feature | RestTemplate | RestClient |
|---|---|---|
| API Style | Template methods | Fluent builder |
| Configuration | Constructor injection | Builder pattern |
| Error handling | ResponseErrorHandler | Status handlers |
| Type safety | Limited | Better with generics |
Migration Examples
1. Basic GET Request
Before (RestTemplate)
@Service
public class ExternalApiService {
private final RestTemplate restTemplate;
public ExternalApiService() {
this.restTemplate = new RestTemplate();
}
public Map<String, Object> getUser(String userId) {
String url = "https://api.example.com/users/" + userId;
ResponseEntity<Map> response = restTemplate.getForEntity(url, Map.class);
return response.getBody();
}
}
After (RestClient)
@Service
public class ExternalApiService {
private final RestClient restClient;
public ExternalApiService() {
this.restClient = RestClient.create();
}
public Map<String, Object> getUser(String userId) {
return restClient.get()
.uri("https://api.example.com/users/{id}", userId)
.retrieve()
.body(new ParameterizedTypeReference<Map<String, Object>>() {});
}
}
2. POST Request with Body
Before (RestTemplate)
public void sendNotification(String userId, String message) {
String url = baseUrl + "/notifications";
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
Map<String, String> payload = Map.of(
"userId", userId,
"message", message
);
HttpEntity<Map<String, String>> request = new HttpEntity<>(payload, headers);
restTemplate.postForEntity(url, request, Void.class);
}
After (RestClient)
public void sendNotification(String userId, String message) {
Map<String, String> payload = Map.of(
"userId", userId,
"message", message
);
restClient.post()
.uri(baseUrl + "/notifications")
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.body(payload)
.retrieve()
.toBodilessEntity();
}
3. Exchange with Custom Headers
Before (RestTemplate)
public Map<String, Object> enrichUserProfile(String userId) {
String url = baseUrl + "/users/" + userId + "/profile";
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
HttpEntity<?> request = new HttpEntity<>(headers);
ResponseEntity<Map> response = restTemplate.exchange(
url,
HttpMethod.GET,
request,
Map.class
);
return response.getBody();
}
After (RestClient)
public Map<String, Object> enrichUserProfile(String userId) {
return restClient.get()
.uri(baseUrl + "/users/{id}/profile", userId)
.accept(MediaType.APPLICATION_JSON)
.retrieve()
.body(new ParameterizedTypeReference<Map<String, Object>>() {});
}
4. DELETE Request
Before (RestTemplate)
public boolean requestDataDeletion(String userId) {
try {
String url = baseUrl + "/users/" + userId + "/data";
restTemplate.delete(url);
return true;
} catch (Exception e) {
return false;
}
}
After (RestClient)
public boolean requestDataDeletion(String userId) {
try {
restClient.delete()
.uri(baseUrl + "/users/{id}/data", userId)
.retrieve()
.toBodilessEntity();
return true;
} catch (Exception e) {
return false;
}
}
RestClient Configuration
Creating a Configured RestClient
@Configuration
public class RestClientConfig {
@Value("${external.api.base-url}")
private String baseUrl;
@Bean
public RestClient restClient() {
return RestClient.builder()
.baseUrl(baseUrl)
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.defaultHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
.build();
}
}
Using the Configured RestClient
@Service
public class ExternalApiService {
private final RestClient restClient;
public ExternalApiService(RestClient restClient) {
this.restClient = restClient;
}
// Methods can now use relative URIs
public Map<String, Object> getUser(String userId) {
return restClient.ge
Установить restclient-migration в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл restclient-migration?
Migrate RestTemplate to RestClient in Spring Boot 3.2+. Use when replacing deprecated RestTemplate with modern fluent API, updating HTTP client code, or configuring RestClient beans. Covers GET/POST/DELETE migrations, error handling, and ParameterizedTypeReference usage.
Как установить скилл restclient-migration?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл restclient-migration запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic