Short update on my DSP project – Being REST-like in WebSharper

Hello everyone, I am extremely busy lately with a few other side projects, so I just wanted to make a small update on my DSP2017 project. I managed to find a few hours today to implement the foundations of a REST-like service in WebSharper. Why am I saying REST-like and not RESTful? Well, because my service only reaches level 2 on the Richardson Maturity Model. I will expand on the subject in a future post, I promise!

The implementation is far from being finished but I finally managed to make a few simple cases work. You can check the code on my GitHub repo under PizzaManagerRestApi.fs. Obviously, the service is about managing pizzas (in case you were still wondering: yes, I like pizzas!). The root URL is http://localhost:9000/pizzamanager/ and for now I implemented two actions:

  • Get the full list of pizzas using /pizzamanager/pizzas.
  • Get a pizza by name by using /pizzamanager/pizza/pizza_name.

You can check out the work in progress in the .gif below:

(click on the .gif to enlarge)

Each call either returns with Success and a Json object or with Failure and an error message, following the now famous Railway Oriented Programming approach (ROP), enabled partly by the simple type Result shown below:

type Result<'T> =
   | Success of 'T
   | Failure of string

If you want to learn more about ROP, I highly recommend you check out this video from the awesome Scott Wlaschin.

As you might have noticed, the Json returned by service is pretty ugly right now:

{
  "result": "success",
  "name": "Margherita",
  "price": 13,
  "ingredients": [
    {
      "name": "Tomato Sauce",
      "quantity": {
        "$": 2,
        "Item": 30
      }
    },
    {
      "name": "Parma Ham",
      "quantity": {
        "$": 1,
        "Item": 100
      }
    },
    {
      "name": "Mozzarella",
      "quantity": {
        "$": 1,
        "Item": 200
      }
    }
  ]
}

I believe this is because of the default way WebSharper serializes to Json to enable communication between the server-side and the client-side. Hopefully we’ll be able to tweak it a little to make it more readable. But that’s the topic of another post.

Until next time!

One thought on “Short update on my DSP project – Being REST-like in WebSharper

  1. Pingback: Being REST-like in WebSharper – Part 2 – Youenn Bouglouan

Leave a Reply

Your email address will not be published. Required fields are marked *