Created
May 13, 2020 23:59
-
-
Save havenwood/a8962410625b57c91896f2bb1f3a991d to your computer and use it in GitHub Desktop.
An example showing the carc.in API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
## | |
# curl --request POST \ | |
# --header "Accept: application/json" \ | |
# --header "Content-Type: application/json" \ | |
# --data "{\"run_request\":{\"language\":\"ruby\",\"version\":\"2.7.0\",\"code\":\"p 2 + 2\"}}" \ | |
# https://carc.in/run_requests | |
require 'net/http' | |
require 'uri' | |
require 'json' | |
URL = URI.parse 'https://carc.in/run_requests' | |
POST = Net::HTTP::Post.new URL | |
CONTENT_TYPE = 'application/json' | |
POST.content_type = CONTENT_TYPE | |
POST['Accept'] = CONTENT_TYPE | |
BODY = { | |
run_request: { | |
language: 'ruby', | |
version: '2.7.0', | |
code: 'p 2 + 2' | |
} | |
}.to_json | |
POST.body = BODY | |
RESPONSE = Net::HTTP.start URL.hostname, URL.port, use_ssl: true do |http| | |
http.request POST | |
end | |
RESPONSE.code | |
#=> 200 | |
PAYLOAD = JSON.parse RESPONSE.body, symbolize_names: true | |
p eval PAYLOAD.dig :run_request, :run, :stdout | |
#>> 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment