Make IDE HTTP server setVar return the the value

Issue #203 resolved
Simon Walters created an issue

Made new issue as I realised that no-one gets notified on extra posts on a resolved issue 🙂

One thing - the new way of setting a variable doesn’t produce any return value like it used to - was that a deliberate design decision or a missing feature?

Comments (16)

  1. Bernat Romagosa

    It doesn’t return any value by design, but maybe that could be changed. @John Maloney , any strong opinions?

  2. John Maloney repo owner

    I don’t have a strong opinion. However, the WebThing spec (https://webthings.io/api/#property-resource) says that the PUT request that sets a property is supposed to return a JSON object containing the property name and value, so we should probably do that if it doesn’t add a huge amount of overhead or code.

  3. John Maloney repo owner

    Are you sure? That new HTTP server doesn’t support PUT requests or the /properties/ URL format as shown in the Snap! blocks.

    If we are talking about the new HTTP server built into the IDE then, yes, I do have a strong opinion. It does not return the value by design. The caller can store the value in a Snap! variable if they want, or do a getVar request to check that it was actually updated.

  4. Bernat Romagosa

    Hmm, you’re right. But the issue title mentions “micro:bit”, so there’s something wrong here. @Simon Walters can you clarify?

  5. Simon Walters reporter

    I am talking about the IDE HTTP server previously called WebThings server before the change on 31Dec20

    The old version did return a JSON object.

    I think that is good thing to do and unless it carries a large overhead, I’d like to see it reverting to previous behaviour.

  6. John Maloney repo owner

    The old HTTP server was based on the WebThing REST API, which was built around JSON. The new HTTP server is not based on the WebThing API. It is much simpler and doesn’t use JSON encodings. The print strings for short lists use square brackets, making them look a bit like JSON, but that’s just a coincidence.

    I’d want to keep the new HTTP server simple and lean.

    What’s the use-case for returning a value from the setVar operation?

  7. Simon Walters reporter

    Use case is just less change to my existing one liner in Snap! 🙂

    I can live without it

    I’ll carry on documenting my project with new method 🙂

  8. John Maloney repo owner

    Thanks for sending that code. I agree, that is a little awkward.

    How would it be if the setVar call just echoed the value – i.e. everything after “setVar/cheerlights/” in the original request. It wouldn’t be a JSON object as it was with the old WebThings server, but it would be the value of cheelights that is stored into the “return” variable in your new implementation.

  9. Log in to comment