If you haven’t lived under a rock last weekend, then you must have heard about ChatGPT. After seeing some impressive tweets and seeing a blog post trending on HackerNews about it, i had to try it out! If you want to try it out, you can do it. All you need is to create an account on openai.com and go to chat.openai.com.
Let’s build a WebApi in F# by just using prompts. This is my Conversation with ChatGPT. The questions are mine, the answers are from ChatGPT (click the ▶ to see the answer):
- Do you know what F# is?
- Can you create a new dotnet webapi project using F# and Giraffe?
- Can you create a user api with 3 endpoints. One to get the user, another one to create a user and another one to list all users?
- Can you use GUID instead of int for the id?
- Can you also use a PostgreSQL database instead of a list and connect to it with Fsharp.Npgsql?
- Can you also add an endpoint to delete a user?
- I would like to put the connectionstring into the appsettings. Can you do that?
- A Dockerfile for the project would be nice :)
- Let's use dotnet SDK version 6 and rename the MyApp to user-api
Recap
I think that’s enough to give you an impression. I am very impressed by this and i am quite happy with the outcome. There were some instances, where the answer would just stop in the middle of the sentence. Here is an example:

This is due to the fact, that the answers are limited to a certain length.
Does the produced code that actually works? No. For example the webapi is not valid Giraffe code:
// Create a route for the GET /users/{id} endpoint
route GET "/users/{id:int}" (fun (id:int) ->
// Find the user with the specified ID
let user = users |> List.tryFind (fun u -> u.Id = id)
// Return a 404 response if the user was not found
match user with
| Some user -> OK user
| None -> NotFound "User not found"
)
But the Model is correct:
// Define a type to represent a user
type User =
{ Id: int
Name: string }
// Define a list of users
let users = [ { Id = 1; Name = "Alice" }
{ Id = 2; Name = "Bob" }
{ Id = 3; Name = "Charlie" } ]