如何使用Chrome的扩展“Advanced Rest Client"测试REST API [英] How to test REST API using Chrome's extension "Advanced Rest Client"

查看:29
本文介绍了如何使用Chrome的扩展“Advanced Rest Client"测试REST API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按照下面链接中的说明,我成功地为我的 Django 应用程序构建了一个 REST API:http://django-rest-framework.org/tutorial/quickstart.

Following the instructions at the link below, I successfully built a REST API for my Django application: http://django-rest-framework.org/tutorial/quickstart.

我可以通过在 Unix 提示符下执行以下操作来测试它:

I can test it by doing the following from the Unix prompt:

curl -H 'Accept: application/json; indent=4' -u root:myPassword http://www.myWebsite.com/users/

它有效:)

但是,我想使用 Chrome 扩展 Advanced Rest Client 来测试相同的功能.我已经安装了扩展程序,但我不知道在哪里/如何放置这些字段.当我进行有根据的猜测时(如您在屏幕截图中所见),它拒绝说未提供身份验证凭据"

However, I would like to use the Chrome extension Advanced Rest Client to test this same functionality. I have installed the extension, but I don't know where/how to put the fields. When I make my educated-guess (as you can see in the screenshot), it rejects it saying "Authentication credentials were not provided"

我应该如何/在哪里为 REST API 指定参数?

How/where should I specify my parameters to the REST API?

推荐答案

可发现性很差,但 Advanced Rest Client 处理基本身份验证的方式非常聪明.亚伯拉罕提到的捷径对我不起作用,但稍微浏览一下就会发现它是如何做到的.

The discoverability is dismal, but it's quite clever how Advanced Rest Client handles basic authentication. The shortcut abraham mentioned didn't work for me, but a little poking around revealed how it does it.

您需要做的第一件事是添加 Authorization 标头:

The first thing you need to do is add the Authorization header:

然后,当您聚焦 value 输入时会弹出一个漂亮的小东西(注意右下角的构造"框):

Then, a nifty little thing pops up when you focus the value input (note the "construct" box in the lower right):

点击它会弹出一个框.如果您愿意,它甚至可以执行 OAuth!

Clicking it will bring up a box. It even does OAuth, if you want!

多田!如果在单击构造"时将值字段留空,它会向其中添加 Basic 部分(我认为它也会添加必要的 OAuth 内容,但我没有尝试,因为我目前的需求是基本身份验证),所以你不需要做任何事情.

Tada! If you leave the value field blank when you click "construct," it will add the Basic part to it (I assume it will also add the necessary OAuth stuff, too, but I didn't try that, as my current needs were for basic authentication), so you don't need to do anything.

这篇关于如何使用Chrome的扩展“Advanced Rest Client"测试REST API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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