- A TCP listener is amongst the basic yet much needed applications in the toolbox of a network manager. TCP Port Listener Tool is a nifty software utility that can create a local listener for any.
- Internet connection measurement for developers. Speedtest CLI brings the trusted technology and global server network behind Speedtest to the command line. Built for software developers, system administrators and computer enthusiasts alike, Speedtest CLI is the first official Linux-native Speedtest application backed by Ookla®.
Featured software trials. Red Hat Ansible Automation Platform. Get the right foundation for operating automation across your organization. Start your free 60-day trial. Red Hat Enterprise Linux. Run your critical workloads on a stable, high-performance, open-source platform. Start your free 30-day trial. Red Hat OpenShift.
(P)Codever is an open source bookmarks and snippets manager for developers & co. See our How To guides to help you get started. Public bookmarks repo on Github -
If you want to quickly test your REST api from the command line, you can use curl. In this post I will present how to execute GET, POST, PUT, HEAD, DELETE HTTP Requests against a REST API. For the purpose of this blog post I will be using the REST api that supports www.codever.land. The API is documented with OpenAPI and available for testing in the browser at https://www.codever.land/api/docs/.
- CRUD Operations on Bookmarks.dev API
In the first part of the blog post I will do a brief introduction to curl and what it can do (HTTP requests with options). In the second part I will show examples with different HTTP operations from bookmarks.dev-api.
What is curl?
Curl is a command line tool and library for transferring data with URL syntax, supporting DICT, FILE, FTP, FTPS, Gopher, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMTP, SMTPS, Telnet and TFTP. curl supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, HTTP/2, cookies, user+password authentication (Basic, Digest, NTLM, Negotiate, Kerberos…), file transfer resume, proxy tunneling and more.
As mentioned, I will be using curl to simulate HEAD, GET, POST, PUT and DELETE request calls against a REST API.
If you want to check if a resource is serviceable, what kind of headers it provides and other useful meta-information written in response headers, without having to transport the entire content, you can make a
Let’s say I want to see what I would GET when requesting latest public bookmarks. I would issue the following HEAD request with curl:
--head- fetch the headers only
-i, --include- include the HTTP response headers in the output
-X, --request- specify a custom request method to use when communicating with the HTTP server (GET, PUT, DELETE&)
Note the following headers
Access-Control-Allow-Headers: Content-Type, Authorization, Location
Access-Control-Allow-Methods: POST, GET, PUT, PATCH, DELETE, OPTIONS
in the response.
They’ve been added to support Cross-Origing Resource Sharing (CORS).
Executing curl with no parameters on a URL (resource) will execute a GET.
which is equivalent with
Note the use of
-H, --header: customer header to pass to the server
If you want to have it displayed prettier I suggest you use a tool like jq:
If you don’t want the progress meter (first part) shown, you can silent curl:
-s, --silent: silent or quiet mode. Don’t show progress meter or error messages. Makes Curl mute. It will still output the data you ask for, potentially even to the terminal/stdout unless you redirect it.
An alternative to jq is to use Python if you have it on your machine:
Curl request with multiple headers
All the responses from the api of bookmarks.dev are gzipped.We could ask for the gzipped variant by issuing the following request:
-v, --verbose: the opposite of
--silent, make the operation more talkative
To achieve that you need to simply add another
-H option with the corresponding value. In this case you would get some unreadable characters in the content, if you do not redirect the response to a file:
CRUD Operations on Bookmarks.dev API
Those were some basic curl HTTP calls with a few options. Now we will combine them and show examples against a productionready API. For the examples I will use the API running on localhost. It is really easy to setup with Docker-compose ifyou follow the instructions from the Readme file.
The API is protected with Keycloak and bearer token. A way to obtain a bearer token in Keycloak is to enable Direct Access Grants for the client - this corresponds to the Resource Owner Password Credentialsin the OAuth2 Specification. Thus the user’s credentials are sent within form parameters. Of course we can do that with curl too:
password are from the initial set up.
The response looks something like the following:
With jq is really easy to extract just the
-d, --data: (HTTP) Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when a user has filled in an HTML form and presses the submit button. This will cause curl to pass the data to the server using the content-type
Create bookmark - POST
Note the Bearer token is reduced here (
Bearer eyJhbGciOiJ....) and in the following examples for brevity
location header - it contains the URL of the new created resource
Read created resource - GET
We will read the previously created bookmark by issuing an GET request on the url from the
Update created resource - PUT
Delete created resource - DELETE
Note the 204 OK Status showing that everything worked as expected.
Trying to execute the deletion again will result in an 404 resource NOT_FOUND status:
The stacktrace is shown because we are in dev modus
Download Api Tester For Mac 1.1 Software
Download Api Tester For Mac 1.12
I am just scratching the surface in this blog post. Check out the curl docs for furthercapabilities.