REST API Editor

abstract REST Client helps to work easily with REST APIs. With REST Client, you can analyze the response returned by REST API and generate Sahi script.


Launching the REST Client

REST Client can be launched by clicking on the REST Client link from Editor.

REST Request

REST request can be entered by one of the following ways:

Manual Input

Specify the following request parts as applicable: Enter the required fields and click on 'Send Request' button to submit the request and get response.

Import from HAR

Import from network activity in Sahi logs

REST Response

REST Response section displays following information:
  1. Response Status: Displays the response code returned by the server.
  2. Response Header: Displays the response headers returned by the server.
  3. Response Body: Response Body has 3 tabs:
    • Raw: Displays the response body as it is returned.
    • HTML: Displays the parsed HTML if content type returned from server is HTML.
    • TREE: Displays the response body in tree structure if content type returned from server is JSON or XML.

Generate Script

Select the parameters which has to be validated by selecting the checkboxes and click on Generate Sahi Script button. For example: select Response Status, Content Type from Request Headers and place_id from Reponse Body and click on Generate Sahi Script.

Authorization

Basic Auth

Enter the username and password after selecting Basic Auth from dropdown.

OAuth 1.0:

Choose OAuth 1.0 from the Authorization dropdown.
  • Credentials: Select an already saved credential or select Add New from credentials dropdown to add a new credential. Enter a friendly name to save these credentials against. Enter the Consumer Key, Consumer Secret, Token, Token Secret. These details are provided by the API provider.
  • Signature Method: Sahi currently supports HMAC-SHA1 and HMAC-SHA256 signature methods.
  • Version: Enter the version as required by the API under test.
  • Realm: Enter the realm as required by the API under test.
  • OAuth 2.0

    info We recommend you to read the article about OAuth 2 - OAuth 2 Simplified by Aaron Parecki if you're new to OAuth 2.
    References:
    OAuth 2 RFChttps://tools.ietf.org/html/rfc6749
    REST APIhttps://techdocs.ed-fi.org/display/ETKB/REST+API+Guidelines+v2.0+RFC
    1. Sahi's OAuth 2 automation can be accessed from the Authorization drop down as shown in the picture below.
    2. This shows the Access Token field.
    3. If you already have a token you can use that to proceed with the API calls. If you do not have an Access Token, click on Get Access Token ... to open the OAuth 2.0 Consent and Access Token Wizard
    4. Choose one of the options:
      OptionUse
      Access Token without Playback/RecordingChoose this if you are just playing around with the REST API and are not intending to record a script
      Playback of recorded consent scriptChoose this if you already have a recorded consent script which enters the relevant data in a browser window to get the Access Token. You may need this to test different APIs by the same provider
      Record a new consent scriptUse this to record the flow on the browser to get the Access Token. This recorded Sahi script is called the consent script
      Using Refresh TokenUse this option if you have a refresh token
    5. Select the Record a new consent script option from the wizard
    6. Give the consent script a name.
    7. Once you click on Proceed, a new browser window will be opened and you will be prompted for authorization information.
    8. You will be redirected to the Login page provided by the authorization endpoint where you have to provide the username, password and permissions to allow access to the user's resources
    9. You will be now prompted with Access Token Request Input form where the Authorization code will be prefilled. Fill rest of the details and click on Get Access Token
    10. After the access token request is successful, the Access Token field in the REST Client UI will be updated
    11. Click on the Send Request button. The Service Endpoint will respond with the API result

    Uploading a file using REST Client

     

    Input

    Description

    Example

    File name

    Absolute file path to the file that should be provided. You can select a file from the File Open dialog by clicking on the button beside the body parameter field

    http://sahitest.com/demo/php/fileUpload.php

    File upload URL

    The URL where you want to upload the file. This URL is usually the action URL which is present in the form element or URL that is passed as an argument for an XML Http Request

    OS

    OS Dependent path example

    Windows

    C:\Users\user\Desktop\upload.txt

    macOS

    /Users/user/Desktop/upload.txt

    Linux

    /home/user/Desktop/upload.txt

    Content Type

    Content type of the POST data that is being sent. The content type for the file upload is multipart/form-data and is being used by all the browsers. There are special cases where you can specify your own content type

    Content-Type: multipart/form-data; boundary=--boundary123456abcd

    Boundary

    A random string with 2 hyphens at the beginning

    --boundary123456abcd

     

    Steps:

    1. Open the Editor from the Sahi Dashboard
    2. Open REST Client by clicking on the More drop down menu
    1. Select the POST from HTTP Method combo box
    1. Specify the file upload URL in the URL field
    1. Specify the Content-Type header in the HTTP Headers table

    1. Specify the POST fields
      1. Specify the file to be uploaded, you can use the browse  button
      2. Specify other body parameters if required, for example on above case, the file upload test application requires 2 other fields for the upload to work
    1. Click on the Send Request button
    2. You will get the following result after the file upload, the response may defer depending on the web application