Mozilla Web Thing Server cURL use instructions are in error

Issue #97 resolved
Turgut Guneysu created an issue

On the microBlocks web page URL http://microblocks.fun/blog-2020-01-15-microblocks,-snap!,-and-the-web there is a section describing the cURL use to read and write properties / variables.

The syntax shown does NOT work in WIN10 command window. The correct syntax is as follows:

BAD:

curl -X PUT "http://localhost:6473/properties/letter" -d '{"letter":"M"}'

GOOD:

curl -X PUT "http://localhost:6473/properties/letter" -d "{""letter"":""M""}”

The difference being:

  • JSON data portion ( -d ) of the command has to have double quotes ( “ ) as delimiter.
    If single quote ( ' ) is used, microBlocks IDE issues a “bad JSON character ' “ error.
  • All strings within the JSON data have to be double-quote delimited.
    If a single double-quote is used, the strings are not parsed correctly and microBlocks IDE issues a “keys have to be strings” error.
    Numeric KEY names have to be double-quoted delimited as well, VALUES are OK without any quotes.

NOTE:

On that web page, there is no cURL GET example. It should be added.

cURL GET to Read a property value:

curl -X GET "http://localhost:6473/properties/letter"

Comments (6)

  1. Bernat Romagosa

    Hi, Turgut. This is an article in a blog, not a manual, so it shouldn’t be expected to be that comprehensive…

    The cURL instructions are for Bash interpreters (Linux, Mac, Unix), not for the Windows command line, which I have no idea about. I see that Windows, for some reason, expects you to double double-quotes, which is surprising to say the least. I’d kind of understand if they required you to escape double quotes, but doubling them is rather odd. If we correct this for Windows, we’ll be breaking it for the rest of the systems, and I’m inclined to think that 95% of Windows users would never open a command line window, so I’d rather stick with the correct instructions for the rest of the OSes.

    Also, there’s no GET example because, as the article says, it’s not needed. You can GET a URL by just typing it in the browser URL bar.

  2. Turgut Guneysu reporter

    Hi Bernat,

    I understand your unfamiliarity with the Windows issues, however the cURL command does exist in Windows as well and if someone wanted to use it they could. The issue was about the correct syntax to use.

    There is nothing to change in any of the programs or systems. I was just informing that if one wants to use this technique in Win, then this is the way the data parameter have to coded. I tested this and it works just fine. Specifying the additional correct syntax for Windows will not break any other OS’s, as there is no change to anything but what the win users have to type.

    Anyway, you guys decide ! I have just reported and provided a way to achieve it.

    By the way, congrats on your new house and good luck with the renovation efforts.

  3. Bernat Romagosa

    Hi, Turgut.

    I added a note for Windows users under the curl command.

    Re: house renovation. Thanks! We’re excited! 🙂

  4. Log in to comment