Home > database >  I am getting false in API query with code 200 with ruby
I am getting false in API query with code 200 with ruby

Time:01-15

Friends, I can't understand what's going on, I'm new to programming.

#Create Employee
  
  @manter_user = Crud.new (my class)

    #Create
      $response = @manter_user.create(my method)
      puts "Response is: #{$response}" 
      puts "Create Response HTTP code 200: #{$response.code == 200}"
    end 
    
    crete ok
    Response is: {"status":"success","data":{"name":"Kip","salary":8037.4700000000002546585164964199066162109375,"age":63,"id":7435},"message":"Successfully! Record has been added."}
          **Create Response HTTP code 200: true**
    #list
      @id = $response.parsed_response["data"]["id"]
      puts  "@id: #{@id} retornado é o mesmo préviamente criado..."
      retrieve_response = @manter_user.retrieve(@id)
      puts "Retrieve Response HTTP code 200: #{retrieve_response.code == 200}"
     end  
    
    List
     **Retrieve Response HTTP code 200: false**

CodePudding user response:

As I mentioned in my previous Answer and the comments below.

The dummy API you are using does not actually store the records you are creating it just provides a dummy response.

These are fake online REST APIs for testing and prototyping sample applications that use rest calls to display listings and crud features. This rest api tutorials, faking a server, and sharing code examples can all be used.

Methods provided by the API:

  • Create - You can "create" a record and receive a fictional response but the record is not persisted.
{"status":"success","data":{"name":"Alva","salary":12,"age":33,"id":1488},"message":"Successfully! Record has been added."}
  • Retrieve an individual record - You can retrieve a single record up to id 24 (a fixed list of records are available). Response differs from other methods. (This will result in a failure of verifying a 200 HTTP status code if you use an id > 24, which would be the case if you are using the id from the previously created record (also see below for another reason))
{"status"=>"success", "data"=>{"id"=>9, "employee_name"=>"Colleen Hurst", "employee_salary"=>205500, "employee_age"=>39, "profile_image"=>""}, "message"=>"Successfully! Record has been fetched."}
  • Update - You can "update" a record with any id and receive a fictional response but the response is malformed JSON making it effectively useless.
{"status"=>"success", "data"=>{"{\"name\":\"Cassia\",\"salary\":\"100000\",\"age\":\"24\"}"=>nil}, "message"=>"Successfully! Record has been updated."}
  • Delete - You can "delete" a record with any id and receive a fictional response.
{"status"=>"success", "data"=>"78", "message"=>"Successfully! Record has been deleted"}

There is no way using this dummy API that you can actually test the full lifecycle of record due to the way it is constructed.

Additionally it appears this API is in the process of being torn down:

  • They are trying to sell the domain and associated code
  • The page regularly shows that it is down, suspended, or under maintenance
  • They recently have implemented request throttling which is now resulting in a HTML response of "Too Many Requests" which will make it more difficult to use for basic testing. (This will also result in a failure if verifying a 200 HTTP code response)
  • Related