API Examples and Documentation

How to use the API
1 Set your API secret in the request header
              
"Authorization": "<your API secret here>"
"Authorization": "2x673rw2366Z400MT2440jSiFV1O0v55"
              
            
2 Specify your API token in the URL
              
"https://www.restwords.com/api/v1/resources/<Your API token here>"
"https://www.restwords.com/api/v1/resources/d332490878fc273cb9dad709ccaUUd"
              
            

3 Make an HTTP GET to retrieve your blob, or a POST to update the blob's value
              
curl -X GET "https://www.restwords.com/api/v1/resources/<API token>" -H  "accept: application/json" -H  "Authorization: <API secret>"
curl -X POST "https://www.restwords.com/api/v1/resources/<API token>" -H "accept: application/json" -H "Authorization: <API secret>" -H "Content-Type: application/json" -d "{ \"blob\": \"updated text goes here\"}"

4 Example response

The response returned from the API's GET request is a simple dictionary containing one key/value pair:


              
{"blob": "Here is my stored text"}
              
            

Note: if POSTING to your endpoint, ensure you use "blob" as the key in your JSON


Python
An example with Python
                

from requests import get
from os import environ


url = "https://www.restwords.com/api/v1/resources/"
token = environ['RESTWORDS_API_TOKEN']
secret = environ['RESTWORDS_API_SECRET']
url += token
h = {"Authorization": secret}

# example GET
response = requests.get(url, headers=h).json()


# example POST
my_new_value = {"blob": "Some new text here"}
response = requests.post(url, headers=h, json=my_new_value).json()


              
              

Your blob can be obtained by the key: response['blob']



C#
An example with C#
                
using System;
using System.Net;
using System.IO;


namespace req {
    class Request {
        static void Main(string[] args) {
            string html = string.Empty;
            string base_url = @"https://www.restwords.com/api/v1/resources/";
            string token = "<API token here>";
            string secret = "<API token here>";
            string url = base_url + token;

            // example POST to change your stored text:
            var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method = "POST";
            httpWebRequest.Headers["Authorization"] = secret;
            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) {
                string json = "{\"blob\":\"Here is my new stored text!\"}";
                streamWriter.Write(json);
                streamWriter.Flush();
                streamWriter.Close();
            }
            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) {
                var resp = streamReader.ReadToEnd();
                Console.WriteLine(resp);
            }

            // example GET to retrieve your stored text:
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Headers["Authorization"] = secret;
            request.AutomaticDecompression = DecompressionMethods.GZip;
            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            using (Stream stream = response.GetResponseStream())
            using (StreamReader reader = new StreamReader(stream)) {
                html = reader.ReadToEnd();
             }
            Console.WriteLine(html);
        }
    }
}
                  
                    

PHP
An example with PHP
                

// A simple example to GET your text blob:
<?php
  $opts = array(
    'http'=>array(
      'method'=>"GET",
      'header'=>"Authorization: <api_secret_here>\r\n"
    )
  );
  $context = stream_context_create($opts);
  $url = 'https://www.restwords.com/api/v1/resources/';
  $url .= '<API token here>';
  $file = file_get_contents($url, false, $context);
  print $file
?>


// A simple example to POST and update your stored blob:
<?php
  $new_data = array('blob' => 'Here is my updated blob!');
  $opts = array(
    'http'=>array(
    'method'=>"POST",
    'content' => json_encode( $new_data ),
    'header'=>"Authorization: <api secret here>\r\n" .
              "Content-Type: application/json\r\n"
    )
  );
  $context = stream_context_create($opts);
  $url = 'https://www.restwords.com/api/v1/resources/';
  $url .= '<api token here>';
  $file = file_get_contents($url, false, $context);
  print $file
?>
                  

Powershell
An example with Powershell
                
# Example GET:

$headers = @{}
$headers.Add("Authorization", "<API secret here>")
Invoke-WebRequest -Uri "https://www.restwords.com/api/v1/resources/<api token here>" -Headers $headers


StatusCode        : 200
StatusDescription : OK
Content           : {"blob":"Here's my stored blob!"
RawContent        : HTTP/1.1 200 OK
                    Connection: keep-alive
                    Vary: Accept-Encoding
                    Strict-Transport-Security: max-age=31536000
                    X-Clacks-Overhead: GNU Terry Pratchett
                    Content-Length: 2012
                    Content-Type: application/jso...
Forms             : {}
Headers           : {[Connection, keep-alive], [Vary, Accept-Encoding], [Strict-Transport-Security, max-age=31536000],
                    [X-Clacks-Overhead, GNU Terry Pratchett]...}
Images            : {}
InputFields       : {}
Links             : {}
ParsedHtml        : mshtml.HTMLDocumentClass
RawContentLength  : 2012


# Example POST:

$headers = @{}
$headers.Add("Authorization", "<API secret here>")
$JSON = @'
{"blob":"store this new updated blob!"}
'@
Invoke-WebRequest -UseBasicParsing https://www.restwords.com/api/v1/resources/<api token here> -ContentType "application/json" -Method POST -Body $JSON -Headers $headers


StatusCode        : 200
StatusDescription : OK
Content           : {"success":"blob updated"}

RawContent        : HTTP/1.1 200 OK
                    Connection: keep-alive
                    Strict-Transport-Security: max-age=31536000
                    X-Clacks-Overhead: GNU Terry Pratchett
                    Content-Length: 27
                    Content-Type: application/json
                    Date: Wed, 22 May 2019...
Forms             :
Headers           : {[Connection, keep-alive], [Strict-Transport-Security, max-age=31536000], [X-Clacks-Overhead, GNU Terry Pratchett], [Content-Length, 27]...}
Images            : {}
InputFields       : {}
Links             : {}
ParsedHtml        :
RawContentLength  : 27