This commit is contained in:
24
docs/snippets/ruby/api/client_extract_single_file.md
Normal file
24
docs/snippets/ruby/api/client_extract_single_file.md
Normal file
@@ -0,0 +1,24 @@
|
||||
```ruby title="Ruby"
|
||||
require 'net/http'
|
||||
require 'json'
|
||||
|
||||
uri = URI('http://localhost:8000/extract')
|
||||
http = Net::HTTP.new(uri.host, uri.port)
|
||||
|
||||
request = Net::HTTP::Post.new(uri)
|
||||
|
||||
File.open('document.pdf', 'rb') do |file|
|
||||
body = file.read
|
||||
request['Content-Type'] = 'application/octet-stream'
|
||||
request.body = body
|
||||
|
||||
response = http.request(request)
|
||||
|
||||
if response.is_a?(Net::HTTPSuccess)
|
||||
data = JSON.parse(response.body)
|
||||
puts JSON.pretty_generate(data)
|
||||
else
|
||||
puts "Error: #{response.code} #{response.message}"
|
||||
end
|
||||
end
|
||||
```
|
||||
Reference in New Issue
Block a user