.NET APIs Part 6 – Swagger

This is part 6 in a series about building APIs in .NET using C#. The previous (part 5) entry is here, and the series starts here.

As you know, an API sits between a client and the back end. It is imperative for the client programmer to know not only what an API does, but what the URL is, what verbs it supports and what parameters are available.

Fortunately, there is an open standard and free server: Open API and Swashbuckle. You install these once for each project and then you can just use them, as we’ll see.

This post will show you how to install them, using Visual Studio. You’ll obtain the bits you need using NuGet. Start by installing Swashbuckle.AspNetCore.

Go to your project’s properties and choose Application and Console Application. Then choose Output under Build and scroll down to where you can check “Generate a file containing API documentation”

Open Program.cs and add the Swagger generator to the services collection:

builder.Services.AddSwaggerGen(
 x =>
 {
     x.SwaggerDoc(
         "v1",
         new OpenApiInfo
         {
             Title = $"{Assembly.GetExecutingAssembly().GetName().Name}",
             Version = "Version 1",
             Description = "Create documentation for myApp",
             Contact = new OpenApiContact
             {
                 Name = "Jesse Liberty",
                 Email = "yourName@gmail.com",
                 Url = new Uri("https://jesseliberty.com")
             }
         });
             var xmlFilename = System.IO.Path.Combine(System.AppContext.BaseDirectory, $"{Assembly.GetExecutingAssembly().GetName().Name}.xml");
             c.IncludeXmlComments(xmlFilename);

});

That's it, you are now ready to create Swagger documentation. We'll review how to do so in the next installment.
Unknown's avatar

About Jesse Liberty

Jesse Liberty has three decades of experience writing and delivering software projects and is the author of 2 dozen books and a couple dozen online courses. His latest book, Building APIs with .NET, is now available wherever you buy your books. Liberty is a Senior SW Engineer for CNH and he was a Senior Technical Evangelist for Microsoft, a Distinguished Software Engineer for AT&T, a VP for Information Services for Citibank and a Software Architect for PBS. He is a Microsoft MVP.
This entry was posted in API, C# and tagged . Bookmark the permalink.

15 Responses to .NET APIs Part 6 – Swagger

  1. fljfojgix's avatar fljfojgix says:

    One of NetEnt’s all-time classic slots gets a makeover in Fruit Shop Megaways. Give this delightful fruit-themed online slot machine a spin to enjoy Megaways slot reels, cascading wins, wilds, and free spins with an increasing multiplier up to 10x the bet. Fruit Shop Megaways is a fast, furious rhythmic game with fun and exciting gameplay despite its simplicity. Persons under the age of 21 are prohibited to play remote table games and on category a gaming machines. Persons under the age of 18 are prohibited to play. Warning: irresponsible gambling may become the cause of gambling addiction. Fruit Shop Megaways is easy to get started playing. Below the reels, you can use the coin button to change your bet per spin which can start from as little as 20p and rises to £100. Once your bet is set, use the middle arrow button to send the reels spinning. As this is a Megaways game, there are up to 1117,649 ways to win and each reel will feature between two and seven symbols. The aim is to get as many symbols on the reels as possible to create more chances of winning combinations. This game has an autoplay feature where you can set your bet per spin and the number of spins you want, up to 1000, before letting the game play automatically.
    https://newsafarihotel.com/login-rewards-timing-for-teen-patti-gold-in-oman-what-to-expect/
    Online casino expert of 9 years. Dermot provides quality and in-depth online casino reviews for Irish casino enthusiasts and the latest iGaming industry news. One of his best works, our New Online Casinos page, has helped many Irish players find the latest casinos to play at. Playing Mega Joker is easy to play, even if you’re still learning how to play slots. We’ve broken down the steps so you’ll know what to do. While the mega joker slot machine relies heavily on luck, players can adopt strategies to maximize their enjoyment and potential returns: SJ VIP Rubbish Removal RTP, or ‘return to player,’ is a crucial metric for any slot game. Mega Joker boasts an astonishing 99% RTP, making it one of the highest paying slot machines. If you want to play the Mega Joker slot game in a real money playing environment, then there are plenty of fully licensed and regulated casinos to choose from, however the one showcased on this guide comes highly recommended.

  2. binance's avatar binance says:

    I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.

  3. Thanks for sharing. I read many of your blog posts, cool, your blog is very good.

  4. Thank you a lot for sharing this with all folks you actually recognise what you are talking approximately! Bookmarked. Please additionally talk over with my website =). We can have a hyperlink trade arrangement among us!

  5. I got what you intend, appreciate it for putting up.

  6. Dry Cleaning's avatar Dry Cleaning says:

    Dry Cleaning in New York city by Sparkly Maid NYC

  7. Completely trustworthy service, trustworthy team members. Trustworthy partners chosen. Consistent appreciation.

  8. I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.

  9. Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me. https://accounts.binance.com/vi/register-person?ref=YY80CKRN

  10. Your article helped me a lot, is there any more related content? Thanks!

  11. Registro's avatar Registro says:

    I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.

  12. list.ly's avatar list.ly says:

    Fascinating and perceptive analysis of the subject matter.
    Your review was extensive and well-referenced, giving subscribers with a comprehensive understanding
    of the essential concerns at fingertips.

    I might be excited to converse supplementary on this
    content. If you approve, I would graciously suggest you to join me on the SBOBET
    site, in which we should extend our conversation in a more responsive space.

    My web site: online casino cybersecurity (list.ly)

  13. The world of rigorous gaming has undergone a remarkable change in recent years, with the rise of esports as a
    global trend . Amidst this rapidly evolving landscape,
    one name has emerged as a innovator – Spade Gaming.

    Spade Gaming is a dominance to be reckoned with, a gaming
    corporation that has carved out a unique
    expertise for itself by blending cutting-edge invention ,
    strategic foresight , and a unwavering commitment to prowess.

    Established with the goal of rethinking the boundaries of
    cutthroat gaming, Spade Gaming has quickly become a exemplar of ingenuity , driving the
    market forward with its unconventional approach and
    unyielding dedication.

    At the center of Spade Gaming’s triumph lies its steadfast drive on player development and unit building.

    The establishment has cultivated an community that encourages and reinforces its performers , providing them with the supplies , instruction , and
    assistance they need to reach new heights .

    But Spade Gaming’s impact extends far beyond the reach
    of the parameters of the game inherently . The corporation has also solidified itself as
    a pacesetter in the discipline of information creation, leveraging its
    vast repository of talented individuals to create
    spellbinding and spellbinding coverage that resonates supporters throughout the planet
    .

    In addition , Spade Gaming’s loyalty to public stewardship and community
    outreach differentiates it one-of-a-kind from its competitors .
    The conglomerate has utilized its stage to raise awareness
    for consequential crusades , deploying its significance and
    prominence to foster a impactful effect in the sphere of esports and stretching wider .

    As the esports sector presses forward to
    advance , Spade Gaming towers as a shining prototype of that which can be realized when planning , originality , and
    a determined pursuit of perfection fuse
    .

    In the epoch to follow , as the world of challenging gaming persists to enthrall
    spectators and reinvent the way we engage with amusement , Spade Gaming will indisputably endure
    at the forefront , pioneering the drive and building a pioneering age in the
    constantly changing realm of esports.

    my web page: online casino player feedback

  14. Andrii's avatar Andrii says:

    I heard that Swashbuckle package don’t support NET8

  15. Pingback: Dew Drop – February 6, 2024 (#4122) – Morning Dew by Alvin Ashcraft

Leave a Reply

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