REST API:搜索包含空格的字符串所使用的正确动词和路径是什么?

huangapple go评论68阅读模式
英文:

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(&quot;/v1/trainers/name/{trainerName}&quot;)
public List&lt;TrainerDTO&gt; 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).

huangapple
  • 本文由 发表于 2023年3月7日 18:24:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/75660719.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定