The RickNMorty.Common package provides a convenient wrapper for interacting with the Rick and Morty API. This package includes services for retrieving character, episode, and location data from the API, making it easier to integrate Rick and Morty data into your .NET applications.
To install the RickNMorty.Common package, use the following command in the Package Manager Console:
Install-Package RickNMorty.Common
Or with .NET CLI:
dotnet add package RickNMorty.Common
Ensure that you have registered the necessary services in your IoC container. The following example demonstrates how to register these services using the built-in dependency injection in ASP.NET Core:
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddHttpClient();
services.AddSingleton<IBaseConfiguration, ApiConfiguration>();
}
}
The CharacterService provides methods to fetch character data from the Rick and Morty API.
public async Task<CharactersResponse> GetAllCharacters(int page)
{
var characters = await characterService.GetAllCharacters(page);
// Use characters as needed
}
public async Task<Character> GetCharacter(int characterId)
{
var character = await characterService.GetCharacter(characterId);
// Use character as needed
}
public async Task<List<Character>> GetCharacters(IEnumerable<int> characterIds)
{
var characters = await characterService.GetCharacters(characterIds);
// Use characters as needed
}
The EpisodeService provides methods to fetch episode data from the Rick and Morty API.
public async Task<EpisodeResponse> GetAllEpisodes(int page)
{
var episodes = await episodeService.GetAllEpisodes(page);
// Use episodes as needed
}
public async Task<Episode> GetEpisode(int episodeId)
{
var episode = await episodeService.GetEpisode(episodeId);
// Use episode as needed
}
public async Task<List<Episode>> GetEpisodes(IEnumerable<int> episodeIds)
{
var episodes = await episodeService.GetEpisodes(episodeIds);
// Use episodes as needed
}
The LocationService provides methods to fetch location data from the Rick and Morty API.
public async Task<Location> GetLocation(int locationId)
{
var location = await locationService.GetLocation(locationId);
// Use location as needed
}
public async Task<List<Location>> GetLocations(IEnumerable<int> locationIds)
{
var locations = await locationService.GetLocations(locationIds);
// Use locations as needed
}
public async Task<LocationResponse> GetLocations(int page)
{
var locations = await locationService.GetLocations(page);
// Use locations as needed
}
This project is licensed under the MIT License - see the LICENSE file for details.
This package uses data provided by the Rick and Morty API.
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
A .NET library for easy integration with the Rick and Morty API. This library provides services to interact with characters, locations, and episodes from the "Rick and Morty" universe.
Wrapper API around the following API
You can install the package via NuGet Package Manager or by using the .NET CLI.
nuget install RickNMorty.API
or
dotnet add package RickNMorty.API
First, install the NuGet package in your project.
In your application's startup or configuration class, register the services provided by the RickNMorty.API library.
using Microsoft.Extensions.DependencyInjection;
using RickNMorty.Common; // Replace with actual namespace
public void ConfigureServices(IServiceCollection services)
{
services.AddTransient<RegistrationContainer>();
}
Now you can inject and use the services in your application components.
Retrieve a list of all characters from the "Rick and Morty" universe.
using RickNMorty.Common; // Replace with actual namespace
public class MyService
{
private readonly ICharacterService _characterService;
public MyService(ICharacterService characterService)
{
_characterService = characterService;
}
public void FetchAllCharacters()
{
var allCharacters = _characterService.GetAllCharacters(1);
// Process the characters
}
}
Retrieve a specific character using their ID.
using RickNMorty.API; // Replace with actual namespace
public class MyService
{
private readonly ICharacterService _characterService;
public MyService(ICharacterService characterService)
{
_characterService = characterService;
}
public void FetchCharacterById(int characterId)
{
var character = _characterService.GetCharacter(characterId);
// Process the character
}
}
Retrieve a specific list of characters using their ID.
using RickNMorty.API; // Replace with actual namespace
public class MyService
{
private readonly ICharacterService _characterService;
public MyService(ICharacterService characterService)
{
_characterService = characterService;
}
public void FetchCharacterById(int characterId)
{
var characterList = new List<int>(){1,2,3}
var character = _characterService.GetCharacters(characterList);
// Process the character
}
}
Retrieve a list of all locations from the "Rick and Morty" universe.
using RickNMorty.Common; // Replace with actual namespace
public class MyService
{
private readonly ILocationService _locationService;
public MyService(ILocationService locationService)
{
_locationService = locationService;
}
public void FetchAllLocations()
{
var allLocations = _locationService.GetLocations(1);
// Process the locations
}
}
Retrieve a specific location using its ID.
using RickNMorty.Common; // Replace with actual namespace
public class MyService
{
private readonly ILocationService _locationService;
public MyService(ILocationService locationService)
{
_locationService = locationService;
}
public void FetchLocationById(int locationId)
{
var location = _locationService.GetLocation(locationId);
// Process the location
}
}
Retrieve a specific location using its ID.
using RickNMorty.Common; // Replace with actual namespace
public class MyService
{
private readonly ILocationService _locationService;
public MyService(ILocationService locationService)
{
_locationService = locationService;
}
public void FetchLocationsById()
{
var locationList = new List<int>(){1,2,3}
var locations = _locationService.GetLocations(locationList);
// Process the location
}
}
Retrieve a list of all episodes from the "Rick and Morty" universe.
using RickNMorty.Common; // Replace with actual namespace
public class MyService
{
private readonly IEpisodeService _episodeService;
public MyService(IEpisodeService episodeService)
{
_episodeService = episodeService;
}
public void FetchAllEpisodes()
{
var allEpisodes = _episodeService.GetAllEpisodes();
// Process the episodes
}
}
Retrieve a specific episode using its ID.
using RickNMorty.API; // Replace with actual namespace
public class MyService
{
private readonly IEpisodeService _episodeService;
public MyService(IEpisodeService episodeService)
{
_episodeService = episodeService;
}
public void FetchEpisodeById(int episodeId)
{
var episode = _episodeService.GetEpisode(episodeId);
// Process the episode
}
}
Retrieve a specific list of episodes using their ID.
using RickNMorty.Common; // Replace with actual namespace
public class MyService
{
private readonly IEpisodeService _episodeService;
public MyService(IEpisodeService episodeService)
{
_episodeService = episodeService;
}
public void GetEpisodesById()
{
var episodesList = new List<int>(){1,2,3}
var episodes = _episodeService.GetEpisodes(locationList);
// Process the location
}
}
If you find any issues or want to contribute, please open an issue or create a pull request on the GitHub repository.
This project is licensed under the MIT License.