|
2 | 2 | [](https://travis-ci.org/adorableio/avatars-api?branch=master)
|
3 | 3 |
|
4 | 4 | ## What is it?
|
| 5 | +This repository contains the [express middleware](https://expressjs.com/en/guide/using-middleware.html#middleware.router) that can be used to host your own avatars service! |
5 | 6 |
|
6 |
| -#### What are avatars? |
7 |
| -Avatars are earthly creatures that serve as proxies for gods. |
8 |
| -In the web world, they just represent people, and they're usually small images. |
| 7 | +Check out [our website](http://avatars.adorable.io/) for more info on (and an interactive demo of) what this service does. |
9 | 8 |
|
10 |
| -Some use photographs of themselves as their avatar. Some people use caricatures of themselves. Others pick their favorite superhero. The sky's the limit. |
11 |
| - |
12 |
| -#### What's an avatar _service_? |
13 |
| -It answers the question "What is this user's avatar?" |
14 |
| -In this way, it provides a consistent representation of that user. |
15 |
| -Across _all_ websites that use that service. Pretty cool, right? |
16 |
| - |
17 |
| -But what if you haven't uploaded your image to that service? |
18 |
| -Then you get a really boring, gray silhouette. |
19 |
| - |
20 |
| -#### So what's the Adorable Avatars service? |
21 |
| -It's an interface to a better universe. With a simple route, your face will be filled with consistently-linked avatar glory! |
22 |
| - |
23 |
| -Huh? _Consistently-linked avatar glory?_ |
| 9 | +## How do I use it? |
| 10 | +First, you'll need to install the package: |
24 | 11 |
|
25 |
| -Whenever you make a request to Adorable Avatars, using an identifier like " [email protected]," we give you an image for you to use on your page. |
26 |
| -Most importantly, it's the same image! Every. Single. Time. |
| 12 | +```bash |
| 13 | +npm install adorable-avatars --save |
| 14 | +``` |
27 | 15 |
|
28 |
| -## Why would I use it? |
29 |
| -What if you're developing a feature like member lists or profiles, but you don't have any images to use? |
30 |
| -Just give us your user's identifier and we'll give you their avatar image! |
31 |
| -That's it. |
| 16 | +Then, use the router middleware within your application: |
32 | 17 |
|
33 |
| -Already have avatars implemented in your application? |
34 |
| -Use Adorable Avatars as a fallback and get rid of those gray silhouettes! |
| 18 | +```js |
| 19 | +// your_server.js |
| 20 | +var express = require('express'); |
| 21 | +var avatarsMiddleware = require('adorable-avatars'); |
35 | 22 |
|
36 |
| -## How do I use it? |
37 |
| -Here's a quick example in Haml: |
38 |
| -```haml |
39 |
| -.user |
40 |
| - %img.avatar(src="http://api.adorable.io/avatar/#{user.name}") |
| 23 | +var myApp = express(); |
| 24 | +myApp.use('/myAvatars', avatarsMiddleware); |
41 | 25 | ```
|
42 | 26 |
|
43 |
| -### Requesting an Avatar |
44 |
| -The most basic request is of the following form: |
| 27 | +That's it! Your server now includes the avatars endpoints! |
| 28 | + |
| 29 | +### Endpoints |
| 30 | +Assuming your server lives at `myserver.com`, and you've configured the middleware as above, you now have the following endpoints: |
| 31 | + |
| 32 | +* `myserver.com/myAvatars/:id` |
| 33 | + * returns an avatar for the provided `id`. |
| 34 | + * `id` can be anything (email, username, md5 hash, as long as it's a valid URI) |
| 35 | + * defaults to 400px |
| 36 | +* `myserver.com/myAvatars/:size/:id` |
| 37 | + * returns an avatar for the provided `id` at the specified `size` |
| 38 | + * size cannot exceed 400px |
| 39 | +* `myserver.com/myAvatars/face/:eyes/:nose/:mouth/:color` |
| 40 | + * Allows you to generate a custom avatar from the specified parts and color |
| 41 | + * e.g. `myserver.com/myAvatars/face/eyes1/nose2/mouth4/DEADBF` |
| 42 | +* `myserver.com/myAvatars/list` |
| 43 | + * returns JSON of all valid parts for the custom endpoint above |
| 44 | + |
| 45 | +## Development |
| 46 | +If you're developing locally, you'll first need to bootstrap (assumes [nvm](https://github.com/creationix/nvm)): |
| 47 | + |
| 48 | +```bash |
| 49 | +# use correct node version |
| 50 | +nvm use |
| 51 | + |
| 52 | +# install dependencies |
| 53 | +npm install |
| 54 | +``` |
45 | 55 |
|
46 |
| - http://api.adorable.io/avatar/<identifier> |
| 56 | +Then, there are several npm scripts that will be useful: |
47 | 57 |
|
48 |
| -Where `identifier` is the unique identifier for your user (name, email, md5, etc.). |
49 |
| -This will serve the image in its default size. |
| 58 | +```bash |
| 59 | +# run the unit tests |
| 60 | +npm run test |
50 | 61 |
|
51 |
| -To request an avatar with specific size, use the following form: |
| 62 | +# run a dev server |
| 63 | +npm run start |
52 | 64 |
|
53 |
| - http://api.adorable.io/avatar/<size>/<identifier> |
| 65 | +# run both a dev server and eslint |
| 66 | +npm run dev |
54 | 67 |
|
55 |
| -So, if you want your friend Bob's avatar, with a height and width of 200px, the URL would be: |
| 68 | +# compile the application |
| 69 | +npm run build |
56 | 70 |
|
57 |
| - http://api.adorable.io/avatar/200/bob |
| 71 | +# run the compiled server |
| 72 | +npm run start:prod |
| 73 | +``` |
58 | 74 |
|
59 | 75 | ## Contributing
|
60 | 76 |
|
61 | 77 | Please read the [contributors' guide](CONTRIBUTING.md)
|
62 | 78 |
|
63 | 79 | ## Open-source Contributors
|
64 | 80 |
|
65 |
| -* [missingdink](https://twitter.com/missingdink): Illustrated the very first avatars! [/avatar/](http://api.adorable.io/avatar/hi_mom) |
| 81 | +* [missingdink](https://twitter.com/missingdink): Illustrated the very first avatars! [Check them out!](http://api.adorable.io/avatar/hi_mom) |
0 commit comments