Coding Challenge #41 - curl
John Crickett
Helping you become a better software engineer by building real-world applications.
This challenge is to build your own version of curl.
So what is curl? It’s a command like tool for transferring data with URLs - for the sake of this challenge though we’re going to focus on it’s use as a tool for sending HTTP requests. As such it’s often used to test or demonstrate RESTful APIs. For example if you want to use the OpenAI API they offer examples using curl in their documentation.
The Challenge - Building Your Own curl
For this challenge we’re going to build a curl clone that is focused on making the HTTP requests we might use for a RESTful API. Our curl clone will be able to connect to a server and send the HTTP methods: GET, DELETE, POST and PUT.
As part of this challenge you will need to refer to the RFC that defines HTTP. To keep the challenge a reasonable size we’re going to focus on HTTP 1.1 as defined in RFC9110.
Step Zero
Like all the best programming languages we’re zero indexed! For this step, I’ll leave you to setup your IDE / editor and programming language of choice. Pick something you are happy writing network code in. Or one you want to learn how to write network code with.
Step 1
In this step your goal is to read the provided URL from the command line and print out the protocol text that would be sent for a GET request. A GET request is defined in Sections 9.3.1 of the RFC.
You’ll need to write the code to parse the URL and extract a few useful bits:
When you run your solution you should get some output like this:
领英推荐
% cccurl <https://eu.httpbin.org/get>
connecting to eu.httpbin.org
Sending request GET /get HTTP/1.1
Host: eu.httpbin.org
Accept: */*
Or:
% cccurl <https://eu.httpbin.org:80/get>
connecting to eu.httpbin.org
Sending request GET /get HTTP/1.1
Host: eu.httpbin.org
Accept: */*
Here we’re going to use httpbin as a useful test site because it supports the methods we want to test.
Continued...
You can find Step 2 and beyond on the Coding Challenges website as build your own curl.
Or if you'd rather get the whole challenge delivered to you inbox every week, you can subscribe on the Coding Challenges Substack.
2 Other Ways I Can Help You:
Software Engineer at Principal Financial Group
1 年Love this challenges
Tech Lead (ReactJS | Ruby on Rails | Spring-Boot | Angular | NodeJS | AWS | Terraform)
1 年can I just say alias curlllll=curl
Software Engineer | Python Enthusiast | AI Nerd | Good Person to Know
1 年I love how unique these projects are - keep them coming!
?? Content for learning | ?? Projects for building | ?? Ideas for getting better | Building Embedded Systems Learning Platform at embeddedforall.com
1 年Saved!