How to use VERB in url

0

2

I am trying to create and API which uses VERB PUT,GET,DELETE

I can use it in curl by this

curl -X DELETE http://localhost:8080/recipes/hi

But how can i use similarly in url

for eg

This works

http://localhost:8080/recipes/hi

But this is not working

http://localhost:8080/recipes/DELETE/foo

How to add verb DELETE in url?

Mounarajan

Posted 2016-03-23T10:31:36.517

Reputation: 133

1Warning - please do not use obscenities in your posts. I've removed it for you. Note that other users may have flagged your post as "rude or abusive" leading to possible rep loss or suspension. Please read Be Nice: "Avoid vulgar terms and anything sexually suggestive" – DavidPostill – 2016-03-23T10:38:30.243

Issues specific to programming and software development are off topic, see On-Topic. Try [SO] but please first read How do I ask a good question?.

– DavidPostill – 2016-03-23T10:39:30.280

Answers

4

You don't.

The HTTP verbs (GET, POST, PUT, DELETE, HEAD, and OPTIONS) are applied to a URL. They are not elements of a URL.

You can see that in your cURL example: curl -X DELETE http://localhost:8080/recipes/hi

Here the HTTP verb is DELETE, while the URL is http://localhost:8080/recipes/hi. Verb and URL: two different things.

In general, when you enter a URL into a browser address bar, it will issue a GET request to that URL. Browsers will issue POST requests when submitting a form on a HTML page with a method="POST" attribute.

<form method="post" action="http://localhost:8080/submit">

If you fill in this form, the browser will submit a POST request to that URL.

Browsers will not, in the normal course of events, issue PUT, DELETE, HEAD, or OPTIONS requests. They can, but it will require scripting with javascript.

TRiG

Posted 2016-03-23T10:31:36.517

Reputation: 1 058