Skip to content

Instantly share code, notes, and snippets.

@havenwood
Created May 13, 2020 23:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save havenwood/a8962410625b57c91896f2bb1f3a991d to your computer and use it in GitHub Desktop.
Save havenwood/a8962410625b57c91896f2bb1f3a991d to your computer and use it in GitHub Desktop.
An example showing the carc.in API
# 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