使用 Postman 测试 REST 持久性端点持久性、测试、Postman、REST

由网友(▓ 兽心°)分享简介:我一直在尝试构建一个安全的 REST 端点来保存(并返回)一个人对象.到目前为止,我有一个方法如下:I have been trying to build a secured REST endpoint to save (and return) a person object. So far I have a me...

我一直在尝试构建一个安全的 REST 端点来保存(并返回)一个人对象.到目前为止,我有一个方法如下:

I have been trying to build a secured REST endpoint to save (and return) a person object. So far I have a method as below:

@RequestMapping(value = "/save/", method = RequestMethod.POST)
public Person save(@RequestBody Person person) {
    return repository.save(person);
}

我一直在尝试使用 Postman 来测试这个端点,但似乎无法以正确的方式构建 URL.应该说我已经成功测试了find(Long id) (/find/{id}) 和findall.

I have been trying to use Postman to test this endpoint, but don't seem to be able to structure the URL in the correct way. I should say that I have successfully tested find(Long id) (/find/{id}) and findall.

http://localhost:8080/api/save?person={"id":2,"first":"Brian","last":"Smith"}

首先,这是构造用于保存对象的端点的正确方法吗? Postman 结构是否正确?

First, is this the correct way to structure an endpoint for saving an object, and is the Postman structure correct?

推荐答案

你的方法是POST.所以你应该像这样传递你的有效载荷.

Your method is POST. So you should pass on your payload like this.

还要确保您提到了您的 Web 应用程序上下文根.如果 api 是您的上下文根,那么您是正确的.但如果是这种情况,请将其更改为一些有意义的名称.

Also make sure that you have mentioned your web application context root. If api is your context root, then you are correct. But if it is the case then change it to some meaningful name.

阅读全文

相关推荐

最新文章