使用 Postman 测试 REST 持久性端点 [英] Using Postman to test REST persistence endpoints

查看:48
本文介绍了使用 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 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.

这篇关于使用 Postman 测试 REST 持久性端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆