Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation around minimal usage of Hello World in Giraffe #497

Open
wallymathieu opened this issue Nov 10, 2021 · 12 comments
Open

Documentation around minimal usage of Hello World in Giraffe #497

wallymathieu opened this issue Nov 10, 2021 · 12 comments
Labels
documentation Request to change or extend documentation PR approved A PR for this issue will get accepted (as long as inline with the comms) question General question

Comments

@wallymathieu
Copy link

wallymathieu commented Nov 10, 2021

Is there a way to use Giraffe in the same style as seen with Suave:

#r "nuget: Suave, 2.6.1"
open Suave

startWebServer defaultConfig (Successful.OK "Hello World!")

?
Especially since we have seen marketing around minimal APIs for C#.

@dustinmoris
Copy link
Member

Unfortunately not but I think Saturn, which is a wrapper around Giraffe has a similar experience:

open Saturn
open Giraffe

let app = application {
    use_router (text "Hello World from Saturn")
}

run app

@dustinmoris dustinmoris added the question General question label Nov 14, 2021
@slang25
Copy link
Member

slang25 commented Nov 15, 2021

+1 to what Dustin has said, what you are asking for is one of the goals Saturn has.

Here is what a minimal hosting bootstrapping for Giraffe might look like (works with .NET 6 & Giraffe 6.0.0-alpha-2):

open Microsoft.AspNetCore.Builder
open Microsoft.Extensions.Hosting
open Giraffe

let builder = WebApplication.CreateBuilder()
builder.Services.AddGiraffe() |> ignore
let app = builder.Build()

app.UseGiraffe(text "Hello World!")
app.Run()

@wallymathieu
Copy link
Author

@dustinmoris the example that @slang25 has looks pretty minimal. It would be really nice to have it documented since it shows what you can do with Giraffe 😄

@dustinmoris dustinmoris reopened this Nov 16, 2021
@dustinmoris dustinmoris added the documentation Request to change or extend documentation label Nov 16, 2021
@TheAngryByrd TheAngryByrd added the PR approved A PR for this issue will get accepted (as long as inline with the comms) label Jul 7, 2023
@klcantrellsep
Copy link

I discovered this issue trying to get Giraffe set up with .NET 7. It was super helpful to see how to do it here, but it'd be even better if it was documented in the readme or docs. P.S. thanks for the great framework!

@TheAngryByrd
Copy link
Member

Send a PR and I’ll merge it!

wallymathieu added a commit to wallymathieu/samples that referenced this issue Aug 27, 2023
@wallymathieu
Copy link
Author

Any thoughts on where to put the documentation? I've added some PRs related to minimal API code on the samples repository.

@TheAngryByrd
Copy link
Member

After some reflection, I'm not sure the example provided above is as comparable to the minimal api docs link provided above.

For example:

var app = WebApplication.Create(args);

app.MapGet("/", () => "Hello World!");

app.Run();

Shows three things.

  1. The object to build your routes upon
  2. Creating routes and outputting data
  3. Starting the listening process

By contrast:

let builder = WebApplication.CreateBuilder()
builder.Services.AddGiraffe() |> ignore
let app = builder.Build()

app.UseGiraffe(text "Hello World!")
app.Run()

It does, 1 and 3, but doesn't do number 2. Given this example, how would I add an additional post route? We do have this basic starting example, it's not as cute as the minimal api example, and probably could be trimmed up based on the example provided but I think also showing how routes get created and being able to add them easily is a better route than playing code golf.

@wallymathieu
Copy link
Author

I agree that the example you show is better. Perhaps the reason why you have MapGet as a thing directly is because that is a route declaration.

@wallymathieu
Copy link
Author

I've updated the sample to be:

open Microsoft.AspNetCore.Builder
open Microsoft.Extensions.Hosting
open Giraffe

let builder = WebApplication.CreateBuilder()
builder.Services.AddGiraffe() |> ignore
let app = builder.Build()
let webApp =
    choose [
        route "/ping"   >=> text "pong"
        route "/"       >=> text "Hello World" ]

app.UseGiraffe(webApp)
app.Run()

since that is more in line with the intent of MapGet.

@TheAngryByrd
Copy link
Member

I think GETs at what I was thinking in my HEAD. Would you PUT that in the PR?

@wallymathieu
Copy link
Author

@wallymathieu
Copy link
Author

Since the minimal hosting API is relatively new, I had to upgrade to net7 as well:
giraffe-fsharp/samples#3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Request to change or extend documentation PR approved A PR for this issue will get accepted (as long as inline with the comms) question General question
Projects
None yet
Development

No branches or pull requests

5 participants