Coding Challenge  #41 - curl

Coding Challenge #41 - curl

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:

  • The protocol - though for the moment we’ll assume this is always going to be HTTP, but you should still check.
  • The host.
  • The port (we can default this to port 80 for HTTP if it is not provided).
  • The path.

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:

  1. I write another FREE newsletter?Developing Skills?that helps you level up the other skills you need to be a great software developer.
  2. I have a course Become a Better Software Developer by Building Your Own Redis Server (Python Edition) which guides you through solving the Redis Coding Challenge in Python.

Anil Shrestha

Software Engineer at Principal Financial Group

1 年

Love this challenges

回复
Md Robiul Hassan

Tech Lead (ReactJS | Ruby on Rails | Spring-Boot | Angular | NodeJS | AWS | Terraform)

1 年

can I just say alias curlllll=curl

Eric Roby

Software Engineer | Python Enthusiast | AI Nerd | Good Person to Know

1 年

I love how unique these projects are - keep them coming!

Veeresh P S

?? Content for learning | ?? Projects for building | ?? Ideas for getting better | Building Embedded Systems Learning Platform at embeddedforall.com

1 年

Saved!

要查看或添加评论,请登录

John Crickett的更多文章

  • From The Challenges - Memcached Server

    From The Challenges - Memcached Server

    ?? ?? Happy Birthday Coding Challenges - Two Years Old! ?? ?? Coding Challenges is turning two this week! To celebrate…

    13 条评论
  • Coding Challenge #85 - Time Zone Converter

    Coding Challenge #85 - Time Zone Converter

    Coding Challenge #85 - Time Zone Converter This challenge is to build your own Time Zone Converter. That is a tool to…

    12 条评论
  • From The Challenges - IRC Client

    From The Challenges - IRC Client

    Welcome To Coding Challenges - From The Challenges! In this Coding Challenges “from the challenges” newsletter I’m…

    5 条评论
  • Coding Challenge #84 - Mandelbrot Set Explorer

    Coding Challenge #84 - Mandelbrot Set Explorer

    This challenge is to build your own Mandelbrot set explorer. The Mandelbrot set is a set of fractals that exhibit great…

    4 条评论
  • From The Challenges - Cat

    From The Challenges - Cat

    Welcome To Coding Challenges - From The Challenges! In this Coding Challenges “from the challenges” newsletter I’m…

    7 条评论
  • Coding Challenge #83 - Markdown Presentation Tool

    Coding Challenge #83 - Markdown Presentation Tool

    Coding Challenge #83 - Markdown Presentation Tool This challenge is to build your own version of Go’s Present or…

    3 条评论
  • From The Challenges - Shell

    From The Challenges - Shell

    Welcome To Coding Challenges - From The Challenges! In this Coding Challenges “from the challenges” newsletter I’m…

    3 条评论
  • Coding Challenge #82 - Markdown To PDF Editor

    Coding Challenge #82 - Markdown To PDF Editor

    Coding Challenge #82 - Markdown To PDF Editor This challenge is to build your own tool to convert markdown to PDF. It…

    14 条评论
  • From The Challenges - Diff

    From The Challenges - Diff

    Welcome To Coding Challenges - From The Challenges! In this Coding Challenges “from the challenges” newsletter I’m…

    7 条评论
  • Coding Challenge #81 - Brainf*ck Interpreter

    Coding Challenge #81 - Brainf*ck Interpreter

    This challenge is to build your own Brainf*ck Interpreter. Just in case you’re wondering, yes the * should be a u, but…

    34 条评论

社区洞察

其他会员也浏览了