# -*- mode: restclient; url-max-redirections: 0 -*- # Emacs restclient examples for httpbin.org # http://httpbin.org/: HTTP Request & Response Service # Returns Origin IP. GET http://httpbin.org/ip # Returns user-agent. GET http://httpbin.org/user-agent User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0 # Returns header dict. GET http://httpbin.org/headers # Returns GET data. GET http://httpbin.org/get?some=example¶ms=for&testing=restclient # Returns POST data. POST http://httpbin.org/post Content-Type: application/json { "jql": "project = HSP", "startAt": 0, "maxResults": 15, "fields": [ "summary", "status", "assignee" ] } # Content type is loosely matched, could be application/vnd.whatever+json GET http://httpbin.org/response-headers?Content-Type=application/vnd.whatever%2Bjson;%20charset=UTF-8 -> on-response (message "dynamic hook called %s %s" (random ) (random )) -> on-response (message "another hook") # Content type is loosely matched, could be application/vnd.whatever+json GET http://httpbin.org/response-headers?Content-Type=application/something%2Bjson # Returns PUT data. PUT http://httpbin.org/put Content-Type: application/json { "name": "emacs", "awesomness": 9042 } # Returns PATCH data. PATCH http://httpbin.org/patch Content-Type: application/xml [ { "replace": "/awesomness", "value": 9043 } ] # Returns DELETE data DELETE http://httpbin.org/delete If-Match: "*" # HTTP Status codes # 404 GET http://httpbin.org/status/404 # 200 GET http://httpbin.org/status/200 # Returns given response headers. GET http://httpbin.org/response-headers?key=val # cookie data. GET http://httpbin.org/cookies Cookie: name=restclient # HTTPBasic Auth. :example-auth := (format "Basic %s" (base64-encode-string (format "%s:%s" "user" "password"))) GET http://httpbin.org/basic-auth/user/password Authorization: :example-auth # Returns some XML GET http://httpbin.org/xml # Test for unicode PUT http://httpbin.org/put Content-Type: application/json { "text": "\u2018a" } # Localhost bug test GET http://localhost:3000 # Magic mode matching test GET http://httpbin.org/response-headers?Content-Type=whatever/braindamage # UTF-8 encoding test PUT http://httpbin.org/put Content-Type: application/json { "text": "привет", "text2": "João Sá", "text3": "João" } # POST http://httpbin.org/post pwd=1234 # : = foo\bar POST http://httpbin.org/post :foo # # Variables # :auth-token = abcd1234 :number := (+ 1 2 3 4) :text := (concat "This is " ":num" "ber") # # Multiline variable referencing another variable # :my-ip = "123.1.1.1" :common-headers = << Authentication: :auth-token User-Agent: MyApp/1.0 | Other app :my-ip Content-type: application/json # # ...and another one :common-body = << { "number": :number, "text": ":text" } # # Now, use them both in request # POST http://httpbin.org/post?q=1 :common-headers :common-body # ...and another example POST http://httpbin.org/post?q=2 :common-headers { "other": "body", "common": :common-body } # File upload PUT http://httpbin.org/put Content-type: text/plain < /etc/passwd # Test for issue #121 POST http://httpbin.org/post {"json": "that looks like header"} # POST http://httpbin.org/post Content-Type: text/xml # GET http://httpbin.org/redirect-to?url=http%3A%2F%2Fexample.com%2F # :cookie=B=db9s6bpclha4g&b=3&s=eq POST http://httpbin.org/post Cookie: :cookie # ================================================================================================ # dynamic per-request hooks # multi-line elisp expression called on completion GET http://httpbin.org/response-headers?Content-Type=application/vnd.whatever%2Bjson;%20charset=UTF-8 -> run-hook (message "dynamic hook called %s %s" (random ) (random )) # set a variable to the value of your ip address using a jq expression GET http://httpbin.org/ip -> jq-set-var :my-ip .origin # multiple elsip hooks on call GET http://httpbin.org/response-headers?Content-Type=application/vnd.whatever%2Bjson;%20charset=UTF-8 -> run-hook (message "hook 1") -> run-hook (message "hook 2") # set basic auth from vars & referencing vars in hooks :user = jack :password = secret :test-me := (format "%s:%s" ":user" ":password") :auth-token := (format "Basic %s" (base64-encode-string (restclient-get-var ":test-me"))) GET http://httpbin.org/basic-auth/jack/secret Authorization: :auth-token -> run-hook (message (format "authenticated with '%s'" (restclient-get-var ":auth-token"))) # saving header like csrf token for future usage GET http://some.api/csrf_token -> run-hook (restclient-set-var-from-header ":csrftoken" "X-CSRF-Token") # use save header POST http://some.api/restricted X-CSRF-Token: :csrftoken