Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Dec 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile How to send JSON requests via ruby on rails?

    Hi,

    Can someone give me some simple tutorials on how to send JSON requests via ruby on rails?
    Kind stomped since the once in my book are kinda old for my version.

  • #2
    New to the CF scene
    Join Date
    Jan 2015
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Please try to google first. Here is the easiest tutorial I saw on the internet: Ruby on Rails: JSON Requests Tutorial ~ icodeya

  • #3
    New to the CF scene
    Join Date
    May 2015
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    require 'net/http'
    
    require 'rubygems'
    require 'json'
    
    @user = 'user@socialtext.com'
    @pass = 'password'
    @host = 'pitchblende.socialtext.net'
    @port = '22222'
    
    @post_ws = "/data/workspaces"
    
    @payload ={
        "name" => "api-workspace",
        "title" => "API Workspace",
        "account_id" => "1"
      }.to_json
      
    def post
         req = Net::HTTP::Post.new(@post_ws, initheader = {'Content-Type' =>'application/json'})
              req.basic_auth @user, @pass
              req.body = @payload
              response = Net::HTTP.new(@host, @port).start {|http| http.request(req) }
               puts "Response #{response.code} #{response.message}:
              #{response.body}"
            end
    
    thepost = post
    puts thepost

  • #4
    New to the CF scene
    Join Date
    Sep 2015
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I also try not request ever
    Soot your help


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •