Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sidhantpanda/xkcd-api

An API wrapper to fetch xkcd comics
https://github.com/sidhantpanda/xkcd-api

api cli nodejs

Last synced: 23 days ago
JSON representation

An API wrapper to fetch xkcd comics

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 [email protected]