Copy as Curl

At work the other day I noticed something new in the Chrome browser developer console. Under the "History" tab, if you right click on a source you are presented with the following menu:

The menu item that intrigued me was "Copy as Curl". For those who are not Unix savvy, curl is a common utility that allows you to fetch a web page without using a browser. It is a very useful tool in web development. When I clicked on Copy as Curl, I pasted this into my terminal:

curl "http://store.apple.com/us/configUpdate/Z0PZ?option.macbookpro_processor_17=065-C1T0&option.macbookpro_storage=065-C1T5&option.macbookpro_usb_superdrive=none&option.apple_thunderbolt_display=none&option.macbook_pro_keyboard_and_os=065-C1TQ&option.iwork_keynote=065-C13G&option.iwork_pages=065-C13D&option.iwork_numbers=065-C13F&option.macbookpro_applecare=none&option.one_to_one=none&option.thunderbolt_to_gigabit_ethernet_adapter=065-C1T6&option.thunderbolt_to_firewire_adapter=065-C1T8&option.vga_adapter=065-C1TC&option.dvi_adapter=none&option.dual_link_dvi_adapter=none&option.magsafe_2_power_adapter_85w=none&option.magsafe_to_magsafe_2_converter=none&option.apple_thunderbolt_cable=none&option.external_storage=none&option.time_capsule=none&option.apple_tv_mac=none&option.printer_offers=none&fcs1=&fcs2=" -H "Cookie: ccl=tBtBE3lJ4LMSEepGlEUjGGOfRSsgiBpkseqQEyb0CJc=; geo=US; s_orientation=%5B%5BB%5D%5D; s_pathLength=homepage%3D1%2Cmac.tab%2Bother%3D1%2Cmacbookpro%3D1%2C; s_invisit_n2_us=3%2C0%2C26; s_vnum_n2_us=3%7C1%2C0%7C1%2C26%7C1; s_orientationHeight=1102; s_fid=6A8B6312B7B0782B-004C16F62E7063B4; s_pv=macbook%20pro%20-%20index%20%28us%29; dssid2=8f95dcd2-f208-42cb-a984-f885dd15ba03; dc=nwk; pxro=2; sfa=us; asmetrics=%257B%2522store%2522%253A%257B%2522sid%2522%253A%2522wHF2F2PHCCCX72KDY%2522%257D%257D; s_cc=true; s_sq=appleusmac%2Cappleusmacbookpro%3D%2526pid%253Dmacbook%252520pro%252520-%252520index%252520%252528us%252529%2526pidt%253D1%2526oid%253Dhttp%25253A%25252F%25252Fstore.apple.com%25252Fgo%25252Fmacbookpro%25252F_1%2526oidt%253D1%2526ot%253DA%2526oi%253D1; s_vi=[CS]v1|28D4C47D85013893-60000116601E60DD[CE]; s_ppv=AOS%253A%2520home%2Fshop_mac%2Ffamily%2Fmacbook_pro%2Fconfig%2C21%2C21%2C1102%2C" -H "Accept-Encoding: gzip,deflate,sdch" -H "Host: store.apple.com" -H "Accept-Language: en-US,en;q=0.8" -H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.93 Safari/537.36" -H "Accept: */*" -H "Referer: http://store.apple.com/us/configure/ME665LL/A?" -H "X-Requested-With: XMLHttpRequest" -H "Connection: keep-alive"  

The command returned gibberish, but I noticed that it had the "Accept-Encoding: gzip,deflate,sdch"" header set, which means the content is compressed. By piping the results into gunzip (and then jsonpp) I was able to get the following:

{
  "body": {
    "replace": {
      "summary": {
        "processorLead": "2.8GHz Quad-core Intel Core i7, Turbo Boost up to 3.8GHz",
        "sizeLead": "15-inch with Retina display",
        "freeShipping": "Free Shipping",
        "productImage": "http://store.storeimages.cdn-apple.com/3411/as-images.apple.com/is/image/AppleInc/mbp2012-step1-macbookpro-select-15-rt?wid=200&hei=200&fmt=png-alpha&qlt=80&.v=1342736003590",
        "instorePickup": "",
        "buyNow": true,
        "compareHeroLead": "15-inch: 2.7GHz Retina display",
        "shipping": " Available to ship<b>:<\/b><br/> <span> 1-3 business days <\/span> ",
        "heroImage": {
          "height": 100,
          "alt": "MacBook Pro",
          "width": 100,
          "srcSet": {
            "src": "http://store.storeimages.cdn-apple.com/3411/as-images.apple.com/is/image/AppleInc/mbp2012-step1-macbookpro-select-15-rt?wid=200&hei=200&fmt=png-alpha&qlt=80&.v=1342736003590",
            "scaleParams1": "wid=100&hei=100&fmt=png-alpha&qlt=95&.v=1342736003590"
          }
        },
        "productTitle": "",
        "prices": {
          "total": "$3,449.00",
          "levies": {
            "store_levy_net_recycle_fee": "",
            "store_levy_net_copyright_levy": ""
          },
          "tax": "$0.00",
          "specials": {}
        },
        "displayName": "MacBook Pro",
        "part": "Z0PZ",
        "options": [
          {
            "isNone": false,
            "isUpgrade": true,
            "value": "065-C1T0",
            "label": "2.8GHz Quad-core Intel Core i7, Turbo Boost up to 3.8GHz",
            "metricsLabel": "2.8GHz Quad-core Intel Core i7, Turbo Boost up to 3.8GHz",
            "option": "option.macbookpro_processor_17"
          },
          {
            "isNone": false,
            "isUpgrade": false,
            "value": "065-C1T2",
            "label": "16GB 1600MHz DDR3L SDRAM",
            "metricsLabel": "16GB 1600MHz DDR3L SDRAM",
            "option": "option.macbookpro_memory"
          },
          {
            "isNone": false,
            "isUpgrade": true,
            "value": "065-C1T5",
            "label": "768GB Flash Storage",
            "metricsLabel": "768GB Flash Storage",
            "option": "option.macbookpro_storage"
          },
          {
            "isNone": true,
            "isUpgrade": false,
            "value": "none",
            "label": "None",
            "metricsLabel": "NONE",
            "option": "option.macbookpro_usb_superdrive"
          },
          {
            "isNone": true,
            "isUpgrade": false,
            "value": "none",
            "label": "None",
            "metricsLabel": "None",
            "option": "option.apple_thunderbolt_display"
          },
          {
            "isNone": false,
            "isUpgrade": false,
            "value": "065-C1TQ",
            "label": "Backlit Keyboard (English) & User's Guide",
            "metricsLabel": "Keyboard/User's Guide",
            "option": "option.macbook_pro_keyboard_and_os"
          },
          {
            "isNone": true,
            "isUpgrade": false,
            "value": "none",
            "label": "None",
            "metricsLabel": "None",
            "option": "option.macbookpro_applecare"
          },
          {
            "isNone": true,
            "isUpgrade": false,
            "value": "none",
            "label": "None",
            "metricsLabel": "None",
            "option": "option.one_to_one"
          },
          {
            "isNone": true,
            "isUpgrade": false,
            "value": "065-C1T6",
            "label": "None",
            "metricsLabel": "NONE",
            "option": "option.thunderbolt_to_gigabit_ethernet_adapter"
          },
          {
            "isNone": true,
            "isUpgrade": false,
            "value": "065-C1T8",
            "label": "None",
            "metricsLabel": "NONE",
            "option": "option.thunderbolt_to_firewire_adapter"
          },
          {
            "isNone": true,
            "isUpgrade": false,
            "value": "065-C1TC",
            "label": "None",
            "metricsLabel": "None",
            "option": "option.vga_adapter"
          },
          {
            "isNone": true,
            "isUpgrade": false,
            "value": "none",
            "label": "None",
            "metricsLabel": "None",
            "option": "option.dvi_adapter"
          },
          {
            "isNone": true,
            "isUpgrade": false,
            "value": "none",
            "label": "None",
            "metricsLabel": "None",
            "option": "option.dual_link_dvi_adapter"
          },
          {
            "isNone": true,
            "isUpgrade": false,
            "value": "none",
            "label": "None",
            "metricsLabel": "NONE",
            "option": "option.magsafe_2_power_adapter_85w"
          },
          {
            "isNone": true,
            "isUpgrade": false,
            "value": "none",
            "label": "None",
            "metricsLabel": "NONE",
            "option": "option.magsafe_to_magsafe_2_converter"
          },
          {
            "isNone": true,
            "isUpgrade": false,
            "value": "none",
            "label": "None",
            "metricsLabel": "None",
            "option": "option.apple_thunderbolt_cable"
          },
          {
            "isNone": true,
            "isUpgrade": false,
            "value": "none",
            "label": "None",
            "metricsLabel": "None",
            "option": "option.external_storage"
          },
          {
            "isNone": true,
            "isUpgrade": false,
            "value": "none",
            "label": "None",
            "metricsLabel": "None",
            "option": "option.time_capsule"
          },
          {
            "isNone": true,
            "isUpgrade": false,
            "value": "none",
            "label": "None",
            "metricsLabel": "None",
            "option": "option.apple_tv_mac"
          },
          {
            "isNone": true,
            "isUpgrade": false,
            "value": "065-C13G",
            "label": "None",
            "metricsLabel": "None",
            "option": "option.iwork_keynote"
          },
          {
            "isNone": true,
            "isUpgrade": false,
            "value": "065-C13D",
            "label": "None",
            "metricsLabel": "None",
            "option": "option.iwork_pages"
          },
          {
            "isNone": true,
            "isUpgrade": false,
            "value": "065-C13F",
            "label": "None",
            "metricsLabel": "None",
            "option": "option.iwork_numbers"
          },
          {
            "isNone": true,
            "isUpgrade": false,
            "value": "none",
            "label": "None",
            "metricsLabel": "None",
            "option": "option.printer_offers"
          }
        ]
      },
      "priceDeltas": {
        "iwork_keynote": {
          "065-C0VW": "[Add $19.99]",
          "065-C13G": ""
        },
        "thunderbolt_to_gigabit_ethernet_adapter": {
          "065-C1T7": "[Add $29.00]",
          "065-C1T6": ""
        },
        "macbookpro_applecare": {
          "none": "",
          "S3137LL/A": "[Add $349.00]"
        },
        "macbookpro_processor_17": {
          "065-C1QY": "[Subtract $250.00]",
          "065-C1T0": ""
        },
        "magsafe_to_magsafe_2_converter": {
          "MD504ZM/A": "[Add $9.99]",
          "none": ""
        },
        "external_storage": {
          "HA384ZM/A": "[Add $229.95]",
          "HA676ZM/A": "[Add $349.95]",
          "none": "",
          "H5187VC/A": "[Add $2,299.00]",
          "H5184VC/A": "[Add $1,099.00]"
        },
        "thunderbolt_to_firewire_adapter": {
          "065-C1T8": "",
          "065-C1T9": "[Add $29.00]"
        },
        "printer_offers": {
          "HA921LL/A": "[Add $129.95]",
          "HA747LL/A": "[Add $149.95]",
          "none": "",
          "H9671LL/A": "[Add $99.95]"
        },
        "macbookpro_storage": {
          "065-C1T5": "",
          "065-C1T4": "[Subtract $400.00]"
        },
        "apple_thunderbolt_display": {
          "MC914LL/B": "[Add $999.00]",
          "none": ""
        },
        "iwork_pages": {
          "065-C13D": "",
          "065-C0VT": "[Add $19.99]"
        },
        "dual_link_dvi_adapter": {
          "MB571Z/A": "[Add $99.00]",
          "none": ""
        },
        "dvi_adapter": {
          "MB570Z/B": "[Add $29.00]",
          "none": ""
        },
        "iwork_numbers": {
          "065-C13F": "",
          "065-C0VV": "[Add $19.99]"
        },
        "time_capsule": {
          "MD033LL/A": "[Add $499.00]",
          "none": "",
          "MD032LL/A": "[Add $299.00]"
        },
        "vga_adapter": {
          "065-C1TD": "[Add $29.00]",
          "065-C1TC": ""
        },
        "macbook_pro_keyboard_and_os": [
          {
            "value": "065-C1TQ",
            "display": "Backlit Keyboard (English) & User's Guide"
          },
          {
            "value": "AZ065-C1TQ",
            "display": "Backlit Keyboard (Arabic) & User's Guide"
          },
          {
            "value": "BQ065-C1TQ",
            "display": "Backlit Keyboard (British) & User's Guide"
          },
          {
            "value": "KQ065-C1TQ",
            "display": "Backlit Keyboard (Danish) & User's Guide"
          },
          {
            "value": "FZ065-C1TQ",
            "display": "Backlit Keyboard (French) & User's Guide"
          },
          {
            "value": "DZ065-C1TQ",
            "display": "Backlit Keyboard (German) & User's Guide"
          },
          {
            "value": "IZ065-C1TQ",
            "display": "Backlit Keyboard (Italian) & User's Guide"
          },
          {
            "value": "JZ065-C1TQ",
            "display": "Backlit Keyboard (Japanese) & User's Guide"
          },
          {
            "value": "NQ065-C1TQ",
            "display": "Backlit Keyboard (Norwegian) & User's Guide"
          },
          {
            "value": "SQ065-C1TQ",
            "display": "Backlit Keyboard (Swedish) & User's Guide"
          },
          {
            "value": "EZ065-C1TQ",
            "display": "Backlit Keyboard (Western Spanish) & User's Guide"
          }
        ],
        "apple_tv_mac": {
          "MD199LL/A": "[Add $99.00]",
          "none": ""
        },
        "one_to_one": {
          "D4213Z/A": "[Add $99.00]",
          "none": ""
        },
        "apple_thunderbolt_cable": {
          "MD861ZM/A": "[Add $39.00]",
          "none": "",
          "MD862ZM/A": "[Add $29.00]"
        },
        "macbookpro_usb_superdrive": {
          "none": "",
          "MD564ZM/A": "[Add $79.00]"
        },
        "magsafe_2_power_adapter_85w": {
          "MD506LL/A": "[Add $79.00]",
          "none": ""
        }
      },
      "creditMessage": "\n\t\t\n\t\n\t\t\n\t\t\t\t\n\t\t        \t\n        \n            \n    \n\t    <a href=\"http://store.apple.com/us/instant_credit\" onclick=\"s_objectID='d20c5aa06359ada965f31c76459ffc72';\"  data-evar1=\"AOS: com.apple.store.application.aspen.components.cto.CTOConfigUpdatePage |  | Astro Link | 0 | AOS: store.apple.com/us/instant_credit\" data-evar30=\"com.apple.store.application.aspen.components.cto.CTOConfigUpdatePage/Astro_Link\" data-prop37=\"AOS: com.apple.store.application.aspen.components.cto.CTOConfigUpdatePage |  | Astro Link | 0 | AOS: store.apple.com/us/instant_credit | com.apple.store.application.aspen.components.cto.CTOConfigUpdatePage: Financing option\">6, 12, or 18 month<br/>special financing<\/a>\n\t\n\n\n            \n        \n    \n\n\t\t        \t\n\t\t\t\t\n\t\t\t\n\t\n\n\n\t"
    },
    "content": ""
  },
  "head": {
    "status": "200",
    "data": {}
  }
}

Overall I thought it was a pretty cool feature. If you are still wondering why that output would be useful, it is because that output is extremely easy to parse from a programming perspective. You could use this to easily build a script that monitored the price for a specific laptop configuration for example.

Well made software provides solutions to needs we don't know about. I don't think I ever thought "I wish there was a way to make an identical request with curl", but now that I know about it, I will use it a ton.

comments powered by Disqus