Introducing JSONBin GitHub Action
Tags: github, ci, githubactions, devops
Published: 2020-04-08 05:32:51

Hi guys, I would like to introduce one of the GitHub Actions that I have implemented during [GitHub Actions Hackathon](https://githubhackathon.com/). BTW, I've received today an email that I have qualified for a GitHub Hackathon prize, so just sent them my post address and will see what I get :)

Briefly about what all these words in a title mean (if you don't know yet):
- GitHub Actions is really powerful tool that can be used as a CI/CD (but not limited to, actually you can do anything you want with it) and if you're still not aware of it I recommend you to know more [here](https://github.com/features/actions), and [here](https://www.edwardthomson.com/blog/github_actions_advent_calendar.html), and [here](https://www.pluralsight.com/courses/building-custom-github-actions/).
- JSONBin is a service where you can store your own bins. Bin means actually URL that returns anything you want. For example, I need some URL that will return `{"greetings":"Hello dev.to!"}`, so I can sign up to [JSONBin](https://jsonbin.io) and create a bin with this response. It will generate URL for me that might look like this - https://api.jsonbin.io/b/5e8d473dab2e011ba969a6db and I can use it for any purpose I need and even share with someone (if I make it public). It can be used to test something in your app or even to store some data there, e.g. work experience or skills that can be used in your portfolio application. Also, JSONBin works with collections, GeoIP, Schema docs, etc. You can find full API Docs [here](https://jsonbin.io/api-reference).

The main idea of this action is to have URL that will return any response you want in JSON format. You can store job information in your bins for future usage or even use this URL in your CI pipeline.

### How to configure
So, let's start from the beginning and configure this action in your repository.
#### Prerequisites
1. Repository in GitHub
2. Account in [JSONBin.io](https://jsonbin.io/)

#### Configuration
1. Go to [API Keys](https://jsonbin.io/api-keys) page at JSONBin.io and create a new key.
2. Go to your repository in GitHub and create a new secret with the name `API_KEY`. [Here](https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets) you can find an information on how to create a secret in your GitHub repository.
3. Go to the root of your repo and create `jsonbin.yml` in `.github/workflows` folder with the following content:
```yaml
name: JSONbin

on: push

jobs:
  jsonbin:
    name: Test JSONbin
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: fabasoad/jsonbin-action@v1.0.1
        id: jsonbin
        with:
          body: '{"workflow": "${{ github.workflow }}", "author": "${{ github.actor }}", "number": "${{ github.run_number }}"}'
          method: 'CREATE'
          api_key: ${{ secrets.API_KEY }}
      - name: Check bin_id
        run: |
          echo "Bin ID = ${{ steps.jsonbin.outputs.bin_id }}"
          echo "URL = ${{ steps.jsonbin.outputs.url }}"
```
Now push your changes, go to `Actions` tab of GitHub repository and wait till job is finished. Take a look at job output to find the generated result:
![](https://i.ibb.co/xG1YKwS/Annotation-2020-04-08-124857.png)
Here is the result of generated link call:
![](https://i.ibb.co/PxRQ6jV/Annotation-2020-04-08-124858.png)

So it returns exactly what we expect. In this example I use `CREATE` method but you can also `UPDATE` and `DELETE` created bin if needed. All documentation you can find in [README](https://github.com/fabasoad/jsonbin-action/blob/master/README.md) of the repository.

#### Link
[JSONBin GitHub Action](https://github.com/marketplace/actions/jsonbin-action)

Please feel free to create any issue (either bug report or feature request), pull request or just leave a comment with the proposition. I would love to hear any feedback. Also, don't forget to _star_ this action ;) Thank you.