Rick and Morty API
repository·master·Indexed 21 days ago
https://github.com/afuh/rick-and-morty-apiA RESTful and GraphQL API providing access to canonical character, location, and episode data from the Rick and Morty TV show. The project includes a typed JavaScript client, data models for core entities, and a server implementation using Express and Apollo Server with MongoDB integration.
What's inside rick-morty-api
- The Rick and Morty API is a RESTful and GraphQL API that provides access to canonical data from the Rick and Morty television show. It includes data for hundreds of characters, locations, and episodes. Developers can interact with the API using standard HTTP requests or through various language-specific client libraries.
Get started with The Rick and Morty API
masterTo begin using the API, consult the official documentation at https://rickandmortyapi.com/documentation for detailed endpoint information and usage guides.Use the JavaScript client
masterThe Rick and Morty API provides a fully typed JavaScript client for easier integration. This client provides access to all API features with type safety.
- GitHub Repository: afuh/rick-and-morty-api-node
- Client Reference: https://javascript.rickandmortyapi.com
Configure the Rick and Morty API server environment
masterThe server uses environment variables for configuration. To run the server with specific settings, ensure the following variables are set in your environment or a
.envfile:NODE_ENV: Determines the database connection string. If set to'test', it uses a-testsuffix on the local MongoDB URI. If set to'production', it uses theDATABASEvariable.DATABASE: The connection string for the MongoDB instance whenNODE_ENVis set to'production'.PORT: The port on which the Express server will listen. Defaults to8080if not provided.
# Example .env file PORT=8080 NODE_ENV=development DATABASE=mongodb://user:pass@remote-host:27017/rickmortyAccess the REST and GraphQL API endpoints
masterOnce the server is running, it exposes two primary interfaces:
- REST API: Available at the
/api/prefix (e.g.,http://localhost:${PORT}/api/). Specific routes are defined in theroutesmodule. - GraphQL API: Available at the default Apollo Server path (usually
/graphql). The server hasintrospectionandplaygroundenabled, allowing you to explore the schema and run queries via a web interface.
Static Assets: Character avatars are served via the
/api/character/avatarendpoint, which maps to the localimagesdirectory.REST → http://localhost:${PORT}/api/ GraphQL → http://localhost:${PORT}${server.graphqlPath}/- REST API: Available at the
Explore community libraries and API collections
masterIn addition to the official JavaScript client, several community-maintained libraries and collections are available for different environments:
Language Clients
- Dart: Rick and Morty API Dart Client
- Elixir: ExShla
- Go: The Rick and Morty API Go client
- Java: Rick and Morty API Java Client
- .NET: Rick.Net or RickAndMorty.Net.Api
- PHP: Rick and Morty API PHP Client
- Python: Python implementation
- R: mortyr
- Ruby: The Rick and Morty API Gem
- Rust: rick-and-morty crate
- Swift: The Rick and Morty API Swift Client
API Collections
- Postman: Postman collection
- Insomnia: Insomnia collection
Access character avatars
masterAttempting to access the character avatar endpoint via
GET /character/avatarwill result in a404 Not Founderror with a standardized error message.GET /character/avatar Status: 404 { "error": "<message.noPage>" }Get the API base endpoints
masterA GET request to the root path (
/) returns a JSON object containing the base URLs for the primary resources:characters,locations, andepisodes. This is useful for discovering the entry points for the different resource collections.GET / { "characters": "<baseUrl>/character", "locations": "<baseUrl>/location", "episodes": "<baseUrl>/episode" }Access core data models for Characters, Locations, and Episodes
masterThe
modelsmodule serves as the central entry point for accessing the data schemas and models for the Rick and Morty API. It exports three primary models:character: Represents character entities.location: Represents location entities.episode: Represents episode entities.
You can import these models to interact with or validate data structures related to these specific entities.
const models = require('./models'); // Accessing specific models const Character = models.character; const Location = models.location; const Episode = models.episode;Reference: Server Environment Variables
masterThe following environment variables control the server's behavior and connectivity.
NODE_ENV - Sets environment (test, production, etc.) DATABASE - MongoDB connection string (used in production) PORT - Port for the Express server (default: 8080)