title: How to deal with a duplicate key from Faker in Ruby
body: <p>How do I loop if Faker generates an existing name for the name field? </p>
  
  <p>The name field is the primary key in this table. When it finds a duplicate name it will generate until it finds a different name. </p>
  
  <pre><code>class Crud
    include HTTParty
    base_uri 'http://dummy.restapiexample.com/api/v1'
  
    def create 
      nome    = Faker::Name.first_name
      salario = Faker::Number.decimal(l_digits: 4, r_digits: 2)
      idade   = Faker::Number.number(digits: 2)
      #note, you should pass body as JSON string
      body = { name: nome, salary: salario, age: idade }.to_json
  
      headers = {
        'Accept' =&gt; 'application/vnd.tasksmanager.v2',
        'Content-Type' =&gt; 'application/json'
      }
  
      self.class.post('/create', body: body, headers: headers) 
    end
  
    def retrieve(id)
      self.class.get("/employee/#{ id }")
    end 
  end
  
  &gt; client = Crud.new 
  &gt; response = client.create
  &gt; id = JSON.parse(response)['id']
  &gt; client.retrieve(id)
  </code></pre>