|
1 | 1 | # Dynamic SVG labels with basic stats for GitHub repositories |
2 | 2 |
|
3 | | -This example shows how to generate simple SVG labels using Lambda, such as the one below: |
| 3 | +This example project serves simple SVG labels using Lambda, such as the one below: |
4 | 4 |
|
5 | 5 | [](https://github.com/claudiajs/claudia/) |
6 | 6 |
|
7 | | -See [repolabels.net](repolabels.net) for a live version of this example, and generate labels for your own repositories. |
| 7 | +See [repolabels.net](https://repolabels.net) for a live version of this example, and generate labels for your own repositories. |
| 8 | + |
| 9 | +This example demonstrates how to: |
| 10 | + |
| 11 | +- Bind method parameters to URL path components (requests are processed as `{owner}/{repo}/{template}`) |
| 12 | +- Customise response content types (this serves `image/svg+xml`) |
| 13 | +- Manage development/testing/production API versions |
| 14 | +- Connect to a third party REST API (github) |
| 15 | + - store keys for development/testing/production access |
| 16 | +- Protect API access using API keys |
| 17 | +- reduce costs by caching results using CloudFront |
8 | 18 |
|
9 | 19 | ## How it works |
10 | 20 |
|
11 | 21 | The code in [web.js](web.js) just connects to the GitHub developer API to retrieve repository statistics, and then |
12 | | -performs a simple string replacement on [SVG template files](svg/). |
| 22 | +performs a simple string replacement on [SVG template files](svg/). The URL request format is: |
13 | 23 |
|
14 | | -This example demonstrates how to: |
| 24 | +``` |
| 25 | +https://<API ID>.execute-api.<REGION>.amazonaws.com/<STAGE>/<OWNER>/<NAME>/<TEMPLATE>.svg |
| 26 | +``` |
| 27 | + |
| 28 | +where: |
| 29 | + |
| 30 | +- `API ID` is the ID of your API (check the `claudia.json` file after deployment) |
| 31 | +- `REGION` is the region where the API is deployed (eg `us-east-1` if you use the standard `package.json`) |
| 32 | +- `STAGE` is the version of the API (eg `dev` or `production`, see the Getting Started section below for more info) |
| 33 | +- `OWNER` is the owner of the GitHub repository you want to create a label for (eg `claudiajs`) |
| 34 | +- `NAME` is the repository name (eg `claudia`) |
| 35 | +- `TEMPLATE` is the name of a file from the [svg](svg) directory used to create the label (eg `large` or `small`) |
| 36 | + |
| 37 | +## Getting started |
| 38 | + |
| 39 | +Create the development version of the API using `npm run start`, and deploy the production version using `npm run release`. |
| 40 | + |
| 41 | +Github limits the rate of unauthenticated requests severely, this example allows you to optionally specify two stage variables to authenticate requests to GitHub, and increase rate limits. Check out your deployed API in the AWS web console, and add two stage variables to the production stage - `githubClientId` and `githubSecret`. [Create a GitHub applications](https://github.com/settings/applications/new) to get access keys. You can optionally also create a development GitHub application and store its keys in the development stage. |
| 42 | + |
| 43 | +You can change the development version and run `npm run deploy`, and you will see that the development version changed, but the production version did not. For example, uncomment `apiKeyRequired: true` in the last line of `web.js` before deploying. This will cause the API calls to require an API key before allowing the request. See [Use an API Key in API Gateway](http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-api-keys.html) for more information on how to create an use an API key. |
15 | 44 |
|
16 | | -- connect to a third party REST API (github) |
17 | | -- store and use third party API keys in stage variables |
18 | | -- use path parameters for API requests (requests are processed as `{owner}/{repo}/{template}`) |
19 | | -- enforce the usage of an API key |
| 45 | +To push the currently released version to production, run `npm run release` again. |
0 commit comments