Skip to content

Instantly share code, notes, and snippets.

@mjallday
Created November 21, 2013 19:28
Show Gist options
  • Select an option

  • Save mjallday/7587991 to your computer and use it in GitHub Desktop.

Select an option

Save mjallday/7587991 to your computer and use it in GitHub Desktop.
Implement HTTP Server Problem

Implement a HTTP server which can respond to the following curl command

curl 'http://127.0.0.1:8000/images' -H 'Origin: http://127.0.0.1:8000' -H 'Accept-Encoding: gzip,deflate,sdch' -H 'Host: 127.0.0.1:8000' -H 'Accept-Language: en-US,en;q=0.8' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.69 Safari/537.36' -H 'Content-Type: application/json' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Referer: http://127.0.0.1:8000/' -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' --data-binary '{"name":"Balanced","src":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJYAAAAQCAMAAADDNnYVAAAAmVBMVEVXWFpfYGJpaWtycnR7e32EhIaNjY+Wlpefn6CipA+mqB2oqKmxsbKztUS6uru8vV/AwW3Dw8TExXvFxnvJyojMzMzR0qPV1dXW1rHa2r7e3t7e38zj49nmpRLmqR/mrSzmrS3msTnnyonnzpfn1rLn27/n38zn49rn5+fox8Xo0tDqk43qnZjqqKTriIHrk43tU0ntXlTuPzMyENYEAAACeklEQVR42q2VC5PTIBDHIUCghquiRhQ9H3enx/k4td//w7nLApvUpDPO+J+W7oNkfyQLFQ+/T4+56d3Tw9UbMq0mmSn29BH8UO0Z7DmvlCDkFmlPJlvBKiGkmVIJsyy71pdy4tfpdPqeq14eDocrMrVoknBTjplqB7DDGssLUOS0JGywXKE2omo4YpilV65N4J1AP3PVc8B60hCYq5aaixd3sQZMO04LlRZYSQlW3MWiy8QjYD3kqteA9axjDQ6EtSYKjbSYPaxAa1g6ZoFlC8DkrRTCU3hwpOpqMFXhyiL/+PY1d7198YpfmG6PyFHrYFH4pB2s+o58S6OmjhV7LukxV47MamWCxHkib4qxjjDrWCIO5+N3GysixYBLpTRpbgUt/ZD2saigvoQltdYKn2lvnRGHYQuL6qaJopTG9y9TLagxfYYleSMyFrXoLtZ5x3usSOMWVpJInQSMLe0MLrwWRMy8wurSayx9GYu55rYHqLo5w2Jq2haxYSWFIxXErvw/WCqE4G3t8lmw4gbWwGnXsPIse0TTdSzeif7fXqKmFmyPgWXPsdBlyY6VfcdyfBSndKnlJ5zYsO5vbu63saiLk1hIpr+wzDLvOxauhg8IOgBnpdI+1iRAQVSqD9fXn3gOH6dW0TZ3WC2gHNdVdSdRUROKJMQZq7QXH6eDdYbOcdqJvBUxCaYUZdNUrLtr0N0aa9WT/UAqzTtQXU5b7pwRV9uxcpRkcRsw1s6fj8kN6zNifdnBGlPmY5QQwhorSRz5WB0ZKx+75STfcB9r8Ohl0u37j7d5Ke+qfMR7g9EyEewAY5evoaoJnGXEdytORmvtZoJkeXZr8g/c6MVVA/xargAAAABJRU5ErkJggg=="}' --compressed

Requirements

  1. The server needs to listen on /images.
  2. It needs to persist POST requests.
  3. It needs to return a list of these requests when a GET is issued.

Bonus

  1. Write some tests.
  2. Briefly explain how would you change this implementation if you wanted to implement this in a production environment.
  3. Briefly explain how would you change this implementation if you wanted to support PUT, DELETE, or PATCH requests to create, update, or delete images.
  4. What would you do if we needed to support uploading large images?
  5. What would you do if we needed to support post-processing these images?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment