2

I want to send a DELETE request to an external API endpoint in a controller of my Sinatra application using nestful gem. I want to delete an event by sending a DELETE request to an endpoint of TeamSnap API. I have defined the following route in controller:

delete '/events/:id' do
  delete 'https://api.teamsnap.com/v3/events/76674685'
end

When the API endpoint is hit with delete action, I get the following error:

*** "Delete" argument "endpoint" needs to be a number

If I send a get request to the API endpoint, I get the correct response. The get request I am using is given below:

get '/events/:id' do
  get 'https://api.teamsnap.com/v3/events/76674685'
end

Can anyone confirm how can we send the DELETE request in the controller and what I am missing?

Thanks in advance!

Faisal Raza
  • 1,337
  • 1
  • 10
  • 16

1 Answers1

0

[Solved]: I sent a DELETE request through Nestful using the following commands:

delete '/events/:id' do
  request = Nestful::Request.new(endpoint, options)
  request.method = 'delete'
  response = request.execute
end

In the above piece of code, endpoint is "https://api.teamsnap.com/v3/events/EVENT_ID" and options is a hash which contains "Content-Type" and "Authorization" headers.

Faisal Raza
  • 1,337
  • 1
  • 10
  • 16
  • 1
    there were no anwers or comments to this. But it is very helpful. Thanks for posting your solution. – thiebo Jun 21 '22 at 05:21