F# Suave / Fable shared code example
This is a simple proof of concept of using F# on both the backend and the frontend and of sharing some code between them. Be sure to check out the blogpost that describes the motivation in more detail.
The backend is a Suave http server application that listens to POST requests on the /test endpoint. It tries to deserialize the body as JSON to a super primitive shopping Cart type (just a record with a Quantity field), calculates the price with any applicable discounts and the returns just the price as a double if everything worked.
The core "business logic", i.e. the data types for Cart, Discount etc and the logic to test if a discount applies are implemented in a separate file that is included by both the frontend and the backend. By sharing one source of truth between them instead of writing the same logic in two different languages for the two worlds, a big source of errors is prevented.
Many thanks to the many contributors/authors of all the pieces that made this possible and the examples on top of which this demonstration was built!