ChuckNorris.Sdk 1.0.4

dotnet add package ChuckNorris.Sdk --version 1.0.4
NuGet\Install-Package ChuckNorris.Sdk -Version 1.0.4
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ChuckNorris.Sdk" Version="1.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ChuckNorris.Sdk --version 1.0.4
#r "nuget: ChuckNorris.Sdk, 1.0.4"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ChuckNorris.Sdk as a Cake Addin
#addin nuget:?package=ChuckNorris.Sdk&version=1.0.4

// Install ChuckNorris.Sdk as a Cake Tool
#tool nuget:?package=ChuckNorris.Sdk&version=1.0.4

ChuckNorris SDK

Build status

alternate text is missing from this package README image

A C# SDK created for the https://api.chucknorris.io/ API (as a very simple example about "creating a SDK" for a friend who is taking his first steps as a developer).

Supported Platforms

  • .NET 7 or greater

Getting Started

ChuckNorris C# SDK for .NET is available on NuGet and it can be installed through the following options:

Package Manager:

>Install-Package ChuckNorris.Sdk 

.NET CLI:

>dotnet add package ChuckNorris.Sdk 

Add ChuckNorris C# SDK to the container

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddChuckNorrisSdk();

Usage examples

Get a random chuck joke.

using System.Net;
using ChuckNorris.Sdk.Client;
using Microsoft.AspNetCore.Mvc;

namespace WebApp.Controllers;

[ApiController]
[Route("[controller]")]
public class ChuckNorrisController : ControllerBase
{
    private readonly IChuckNorrisClient _client;

    public ChuckNorrisController(IChuckNorrisClient client)
    {
        _client = client;
    }

    [HttpGet]
    public async Task<IActionResult> GetRandomJoke()
    {
        var response = await _client.GetRandomChuckJokeAsync();
        
        if (response.IsSuccessful)
        {
            return Ok(response.ChuckJoke!.Value);
        }

        var problemDetails = new ProblemDetails
        {
            Status = (int)HttpStatusCode.BadGateway,
            Title = "Downstream call failed",
            Detail = "An error occurred while calling https://api.chucknorris.io API."
        };

        return new ObjectResult(problemDetails);
    }
}

Get a list of available categories.

var response = await _client.GetCategoriesAsync();

var categories = response.Categories;

Get a random chuck joke given a category.

var response = await _client.GetChuckJokeByCategoryAsync("sport");

var joke = response.ChuckJoke!.Value;

Get chuck jokes by using full text search.

var response = await _client.SearchChuckJokeByTextAsync("dev");
        
var total = response.TextSearchResult!.Total;

Console.WriteLine($"{total} chuck jokes found!");

var result = response.TextSearchResult!.Result;

foreach (var joke in result)
{
    Console.WriteLine(joke.Value);
}

Contribute

Coming soon!

Problems?

If you find an issue, please visit the issue tracker and report the issue.

Please be kind and search to see if the issue is already logged before creating a new one. If you're pressed for time, log it anyways.

When creating an issue, clearly explain

  • What you were trying to do.
  • What you expected to happen.
  • What actually happened.
  • Steps to reproduce the problem.

Also include any other information you think is relevant to reproduce the problem.

Copyright (c) Guillermo Exposito 2023

Licensed under the Apache License 2.0

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.4 226 10/14/2023