英文:
REST API: Correct verb and path to use for searching by a String that includes a space?
问题
我想要实现一个REST端点,用于获取与特定名称匹配的所有训练师。
名称字段包括名字和姓氏,例如Joe Bloggs
。
以下实现是否正确?有更好的替代方法吗?
// v1/trainers/name/Joe Bloggs
@GetMapping("/v1/trainers/name/{trainerName}")
public List<TrainerDTO> findTrainersByName(@PathVariable String trainerName) {
return trainerService.findTrainersByName(trainerName);
}
英文:
I want to implement a REST
endpoint that gets all Trainers
that match a certain name.
The name field is both first and last name, e.g. Joe Bloggs
Is the following implementation correct? What is a better alternative?
// v1/trainers/name/Joe Bloggs
@GetMapping("/v1/trainers/name/{trainerName}")
public List<TrainerDTO> findTrainersByName(@PathVariable String trainerName) {
return trainerService.findTrainersByName(trainerName);
}
答案1
得分: 1
你可以在这里找到答案。
TLDR:引入空格(或等效字符)的常见方法是使用空格,并用%20转义(Joe%20Blogs),或使用短划线(Joe-Blogs)。
英文:
You can find the answer here.
TLDR: The common way to introduce the space (or equivalent) is to use spaces, escaped as %20 (Joe%20Blogs) or use dashes (Joe-Blogs).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论