jikan-rest/README.MD

196 lines
10 KiB
Plaintext
Raw Normal View History

2018-12-17 11:53:13 +05:00
![Jikan](http://i.imgur.com/ctoJ3Jp.png)
# Jikan - Unofficial MyAnimeList.net REST API
[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/jikan-me/jikan-rest.svg)](http://isitmaintained.com/project/jikan-me/jikan-rest "Average time to resolve an issue") [![Percentage of issues still open](http://isitmaintained.com/badge/open/jikan-me/jikan-rest.svg)](http://isitmaintained.com/project/jikan-me/jikan-rest "Percentage of issues still open") [![stable](https://img.shields.io/badge/PHP-^%207.1-blue.svg?style=flat)]() [![Discord Server](https://img.shields.io/discord/460491088004907029.svg?style=flat&logo=discord)](https://discord.gg/4q8E4Gg)
2018-04-21 13:28:44 +05:00
2018-12-17 11:53:13 +05:00
Jikan is a REST API for [MyAnimeList.net](https://myanimelist.net). It scrapes the website to satisfy the need for an API - which MyAnimeList lacks.
2018-04-21 13:28:44 +05:00
2018-12-17 11:53:13 +05:00
The raison d'être of Jikan is to assist developers easily get the data they need for their apps and projects without having to depend on the lackluster official API, unstable APIs, or sidetracking their projects to develop parsers.
2018-04-21 13:28:44 +05:00
2018-12-17 11:53:13 +05:00
The word _Jikan_ literally translates to _Time_ in Japanese (**時間**). And that's what this API saves you of. ;)
2018-04-21 13:28:44 +05:00
2018-12-17 11:53:13 +05:00
**Notice**: Jikan does not support authenticated requests. You can not update your lists.
## Getting Started
### Requirements
- PHP 7.1+
2019-03-03 14:48:08 -08:00
- [Composer](https://getcomposer.org/download/)
2018-12-17 11:53:13 +05:00
- [Redis](https://redis.io)
2019-05-08 01:08:25 +05:00
#### 🐳 Docker
2019-05-08 01:11:40 +05:00
- [JikanREST Docker](https://github.com/fethica/jikan-rest-docker) by Fethi El Hassasna
2019-08-18 14:33:43 +05:00
- [JikanDocerized](https://github.com/zunjae/JikanDockerized) by Zunjae
2019-05-08 01:08:25 +05:00
2019-07-01 16:50:22 +05:00
### 01. Prerequisites
2019-07-01 16:50:22 +05:00
#### 01A. Linux
This is specifically for Ubuntu, but other distributions should work similarly.
1. Install requirements:
- Add PHP related packages: `sudo add-apt-repository -y ppa:ondrej/php`
- If `add-apt-repository` is not installed, you can install it by doing `sudo apt install python-software-properties` or `sudo apt install software-properties-common`
- `sudo apt update && sudo apt upgrade`
- Install requirements: `sudo apt install curl git php redis unzip`
- Verify that PHP 7.1+ is installed: `php -v`
- Install the corresponding `php-xml` and `php-mbstring` packages for your version, e.g:
- PHP 7.1: `sudo apt install php7.1-xml php7.1-mbstring`
- PHP 7.3: `sudo apt install php7.3-xml php7.3-mbstring`
- Install composer: `curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer`
2. Start the redis server: `sudo service redis start`
2019-07-01 16:50:22 +05:00
#### 01B. Mac
1. Install [brew](https://brew.sh/)
2. Install requirements: `brew install php composer redis`
3. Start the redis server: `brew services start redis`
2019-07-01 16:50:22 +05:00
### 02. Installation
2018-12-17 11:53:13 +05:00
1. `git clone https://github.com/jikan-me/jikan-rest.git`
2. `cd jikan-rest`
3. `cp .env.dist .env`
5. `composer install` (Make sure Jikan's directory has write permissions)
2019-07-01 16:50:22 +05:00
### 03. Configuration
You're able to configure Jikan through the `.env` file.
A few kernel commands are available from the project directory by running the `artisan` file.
The first thing you need to do is generate an `APP_KEY`.
1. `php artisan key:generate`
2019-07-01 09:54:36 -07:00
2. [Configure how Jikan caches](https://github.com/jikan-me/jikan-rest#05-configuring-how-jikan-caches-optional)
3. [Configure how Jikan handles expired cache](https://github.com/jikan-me/jikan-rest#06-configuring-how-jikan-handles-expired-cache-optional)
2019-07-01 16:50:22 +05:00
### 04. Ignition
2019-07-01 17:14:35 +05:00
`php artisan serve --port=8080` or `php -S localhost:8000 -t public`
2019-07-01 17:09:02 +05:00
Jikan is now hosted on `http://localhost:8000/v3/`
2019-07-01 17:14:35 +05:00
**Alternatively,** host it on Apache (or Nginx)
2019-07-01 17:14:35 +05:00
Create a virtual host and point it to `/public`. Jikan supports Apache out of the box, you just need to create a virtual host and point it to `/public`, and enable the rewrite module for .htaccess (`sudo a2enmod rewrite`), and configure `/etc/apache/apache2.conf` by setting `AllowOverride None` to `AllowOverride All` for the `/var/www` directory.
2019-07-01 17:09:02 +05:00
2019-07-01 17:14:35 +05:00
:information_source: If you wish to configure it for Nginx or anything else, you'll have to port the rewrite rules located at `public/.htaccess`
2019-07-01 16:50:22 +05:00
### 05. Configuring how Jikan Caches (optional)
Jikan caches on file by default in `/storage/framework/cache`. So even if you don't change the caching method, Jikan will work out of the box.
However, you can configure Jikan to cache on Redis instead: `php artisan cache:driver redis`
Note: If you're currently running Jikan, you're required to stop it before running the above command.
2019-07-01 17:04:02 +05:00
### 06. Configuring how Jikan handles expired cache (optional)
Jikan handles cache in the `legacy` manner out of the box. This method was used previously to update cache.
2019-05-15 23:37:08 +05:00
2019-07-01 17:04:02 +05:00
#### 06A. Cache Method: Legacy
When a cache expires, it gets deleted. So if you make a request that has an expired cache, your request will take longer as Jikan has to fetch and parse the new data from MyAnimeList again.
2019-07-01 17:04:02 +05:00
#### 06B. Cache Method: Queue
This is a newly introduced caching method to the API, it's what the public API runs on as well. It requires some further setup.
When a cache expires, it does not get deleted. Instead, if you make a request that has an expired cache, a job will be dispatched to the queue which handles updating the cache in the background. Therefore, the request will keep on providing stale cache until the job is complete and the cache is replaced with fresh data.
This method provides zero delay, and is highly recommended if you have immense traffic coming your way.
2019-07-01 16:45:20 +05:00
:information_source: Note: If you're currently running Jikan, you're required to stop it before running the above command. You're also required to clear any cache you've stored as well as anything on the Redis server.
1. `php artisan cache:method queue`
Next, you need to make sure that there's a service looking after the queue. This can be manually done by running a process through `php artisan queue:work --queue=high,low`. You can set the command to run on cron, nohup, etc.
But a recommended way is to install Supervisor and have it handle the queue automatically.
2019-07-01 16:45:20 +05:00
:information_source: Note: `--queue=high,low`; Jikan stores two types of queues; high priority and low priority. This depends on the type of request. You can check which request is considered to be high priority in the [JikanResponseHandler.php](https://github.com/jikan-me/jikan-rest/blob/master/app/Http/Middleware/JikanResponseHandler.php) middleware in the `HIGH_PRIORITY_QUEUE` array.
2019-07-01 16:45:20 +05:00
:information_source: Note 2: Not all requests are queuable. Some are handled the `legacy` way. You can find out which ones in the [JikanResponseHandler.php](https://github.com/jikan-me/jikan-rest/blob/master/app/Http/Middleware/JikanResponseHandler.php) middleware in the `NON_QUEUEABLE` array.
This reason for this is quite simple. User related requests such as anime/manga list can be frequently updated. They're cached by default for 5 minutes (you can change this in `.env`). But if they were to get queued for a cache update, it would take longer than 5 minutes because the update job would have to wait in line. So it skips the queue and is automatically updated on the request. This does mean a slight delay in fetching and parsing the fresh data from MyAnimeList.
2019-07-01 16:45:20 +05:00
:information_source: Note 3: Note 1 & Note 2 are default behavior. You can obviously change them as per your needs.
2019-07-01 17:04:02 +05:00
##### Configuring Supervisor
2019-07-01 17:04:02 +05:00
###### Linux
2019-07-01 17:09:02 +05:00
1. Install supervisor
- Linux: `sudo apt install supervisor`
- Mac: `brew install supervisor`
2. `sudo cp conf/supervisor/jikan-worker.conf /etc/supervisor/conf.d`
- A default supervisor configureation file is available in this repo `conf/supervisor/jikan-worker.conf`
- Be sure to update to the correct directory in `jikan-worker.conf` for `command` and `stdout_logfile` to the directory of jikan!
Example: If I install Jikan in `/var/www/jikan-is-installed-here`, you will have to adjust the following values in the `jikan-worker.conf` file.
```
...
command=php /var/www/jikan-is-installed-here/artisan queue:work --queue=high,low
...
stdout_logfile=/var/www/jikan-is-installed-here/storage/logs/worker.log
stderr_logfile=/var/www/jikan-is-installed-here/storage/logs/worker.error.log
```
3. `sudo supervisorctl reread`
2019-05-15 23:37:08 +05:00
4. `sudo supervisorctl update`
5. `sudo supervisorctl start jikan-worker:*`
2019-07-01 17:04:02 +05:00
###### Mac
1. Install Supervisor: `brew install supervisor`
2. `supervisord -c /usr/local/etc/supervisord.ini`
3. Copy `conf/supervisor/jikan-worker.conf` to `/usr/local/etc/supervisor.d/`
4. `brew services start supervisor`
5. `sudo supervisorctl update`
6. `sudo supervisorctl start jikan-worker:*`
2019-05-15 14:08:18 +05:00
2019-08-19 01:23:14 +05:00
### Troubleshooting
Please read the [troubleshooting guide](https://github.com/jikan-me/jikan-rest/blob/master/TROUBLESHOOTING.md).
2019-08-19 01:25:22 +05:00
For any additional help, join our [Discord server](https://discord.gg/4q8E4Gg).
2019-05-15 14:08:18 +05:00
### Information
2018-12-17 11:53:13 +05:00
If you don't want to host your instance, there's a public API available.
- **[REST DOCUMENTATION](https://jikan.docs.apiary.io)**
- **[Apps/Projects using JikanREST](https://jikan.moe/showcase)**
2019-05-08 01:11:40 +05:00
### Wrappers
2018-12-17 11:53:13 +05:00
- **[.NET]** [Jikan.net](https://github.com/Ervie/jikan.net) by Ervie
- **[Python]** [JikanPy](https://github.com/AWConant/jikanpy) by Andrew Conant & Abhinav Kasamsetty
- **[Ruby]** [Jikan.rb](https://github.com/Zerocchi/jikan.rb) by Zerocchi
- **[JavaScript]** [JikanJS](https://github.com/zuritor/jikanjs) by Zuritor
- **[Java]** [Jikan4java](https://github.com/Doomsdayrs/Jikan4java) by Doomsdayrs
2019-02-14 09:34:30 +01:00
- **[PHP]** [jikan-php](https://github.com/janvernieuwe/jikan-jikanPHP) by Jan Vernieuwe
2019-02-16 03:14:00 -08:00
- **[Node.js]** [jikan-node](https://github.com/xy137/jikan-node) by xy137
2019-05-08 01:11:40 +05:00
- **[Dart]** [jikan-dart](https://github.com/charafau/jikan-dart) by Rafal Wachol
- **[TypeScript]** [jikants](https://github.com/Julien-Broyard/jikants) by Julien Broyard
2019-08-18 14:33:43 +05:00
- **[TypeScript]** [jikan-client](https://github.com/javi11/jikan-client) by Javier Blanco
2018-12-17 11:53:13 +05:00
2019-05-08 01:11:40 +05:00
[Add your wrapper here](https://github.com/jikan-me/jikan/edit/master/readme.md)
2018-12-17 11:53:13 +05:00
### Running Tests
`php vendor/bin/phpunit tests`
Note: Tests may fail due to rate limit from MyAnimeList (HTTP 429)
2019-06-02 14:46:35 +05:00
---
# Backers
Thank you to all our backers! 🙏 [[Become a backer](https://patreon.com/jikan)]
- [PurplePinapples](https://github.com/purplepinapples/)
- [Barkdoll (Jesse)](https://github.com/barkdoll/)
2019-06-20 10:33:51 +05:00
- [Piotr Szymczak (Drutol)](https://github.com/Drutol)
2019-08-24 06:26:37 -07:00
- [Jason Weatherly (jamesthebard)](https://twitter.com/jamesthebard)
2019-06-02 14:46:35 +05:00
# Sponsors
Thank you to all our sponsors! You will recieve advertisement/promotive perks. [[Become a sponsor](https://patreon.com/jikan)]
- [Hibiki Matsujo](https://github.com/assintates)
---
2018-12-17 11:53:13 +05:00
## DISCLAIMER
- Jikan is not affiliated with MyAnimeList.net
- You are responsible for the usage of this API. Please be respectful towards MyAnimeList's [Terms Of Service](https://myanimelist.net/about/terms_of_use)