https://github.com/sidhantpanda/xkcd-api
An API wrapper to fetch xkcd comics
https://github.com/sidhantpanda/xkcd-api
api cli nodejs
Last synced: 12 months ago
JSON representation
An API wrapper to fetch xkcd comics
- Host: GitHub
- URL: https://github.com/sidhantpanda/xkcd-api
- Owner: sidhantpanda
- License: mit
- Created: 2016-08-02T06:34:57.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2022-12-09T19:26:26.000Z (over 3 years ago)
- Last Synced: 2025-04-24T05:26:40.969Z (about 1 year ago)
- Topics: api, cli, nodejs
- Language: JavaScript
- Homepage:
- Size: 43.9 KB
- Stars: 11
- Watchers: 2
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# xkcd-api
An API wrapper and CLI tool to fetch xkcd comics.
```
$ npx xkcd-api
```
```
$ npm install xkcd-api
```
```javascript
$ var xkcd = require('xkcd-api');
```
### APIs available
* [Get the latest comic](#get_latest)
* [Get a particular comic](#get_comic)
* [Get a random comic](#get_random)
### CLI equivalent
* [Get the latest comic](#get_latest_cli)
* [Get a particular comic](#get_comic_cli)
* [Get a random comic](#get_random_cli)
### Get the latest comic
```javascript
xkcd.latest(function(error, response) {
if (error) {
console.error(error);
} else {
console.log(response);
}
});
```
### Get a particular comic
```javascript
xkcd.get('comic-id', function(error, response) {
if (error) {
console.error(error);
} else {
console.log(response);
}
});
```
### Get a random comic
```javascript
xkcd.random(function(error, response) {
if (error) {
console.error(error);
} else {
console.log(response);
}
});
```
## CLI Features
Please make sure you've installed the package globally or are running it with npx.
### Get the latest comic (CLI)
```
xkcd-api
xkcd-api -l
xkcd-api --latest
```
### Get a particular comic (CLI)
```
xkcd-api -n 1714
xkcd-api --number 1714
```
### Get a random comic (CLI)
```
xkcd-api -r
xkcd-api --random
```
---
### Contributors
[Štefan Jarina](https://github.com/stefanjarina)
[justchen1369](https://github.com/justchen1369)
---
### Submit issues
You can raise an issue in this repo or mail me at sidhant@hashexclude.com