rawongithub/grapethor

View on GitHub
README.md

Summary

Maintainability
Test Coverage
[![Gem Version](https://badge.fury.io/rb/grapethor.svg)](https://badge.fury.io/rb/grapethor)
[![Build Status](https://travis-ci.org/rawongithub/grapethor.svg?branch=master)](https://travis-ci.org/rawongithub/grapethor)
[![Maintainability](https://api.codeclimate.com/v1/badges/15145f8728d14b65b42c/maintainability)](https://codeclimate.com/github/rawongithub/grapethor/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/15145f8728d14b65b42c/test_coverage)](https://codeclimate.com/github/rawongithub/grapethor/test_coverage)

# GrapeThor

Grape REST-like API generator based on Thor.

## Installation

Install it yourself as:
```
$ gem install grapethor
```

## Usage

### Get some help

```
$ grapethor help

Commands:
  grapethor api VERSION               # Creates new API within application
  grapethor endpoint RESOURCE [NAME]  # Creates new Endpoint within API
  grapethor help [COMMAND]            # Describe available commands or one specific command
  grapethor new NAME                  # Creates new Grape application
  grapethor resource NAME             # Creates new Resource within API
  grapethor version                   # Displays Grapethor version
```

### Create application
```
$ grapethor help new

Usage:
  grapethor new NAME

Options:
  -p, [--path=PATH]                # Relative path to place application directory
                                   # Default: .
  -x, [--prefix=PREFIX]            # Add Application URL prefix
                                   # Default: api
  -d, [--db=DB]                    # Use specific database
                                   # Default: sqlite
                                   # Possible values: sqlite, postgresql, mysql
  -o, [--orm=ORM]                  # Use specific ORM
                                   # Default: activerecord
                                   # Possible values: activerecord
  -s, [--server=SERVER]            # Preconfigure web server
                                   # Default: thin
                                   # Possible values: thin, puma
  -t, [--test=TEST]                # Use specific test framework
                                   # Default: minitest
                                   # Possible values: minitest, rspec
      [--docker], [--no-docker]    # Use docker
                                   # Default: true
  -l, [--license=LICENSE]          # Add software license information
                                   # Default: mit
                                   # Possible values: mit, apache2, freebsd, newbsd, gpl2, gpl3, mpl2, cddl1, epl1
  -c, [--copyright=COPYRIGHT]      # Add copyright information within license file
  -r, [--ruby=RUBY]                # Ruby version for application
                                   # Default: 2.5.3 (current ruby version)
      [--swagger], [--no-swagger]  # Generate swagger documentation and install swagger-ui
                                   # Default: true
```
License types available for `--license` option:

- `mit`     - [MIT License](http://opensource.org/licenses/MIT)
- `apache2` - [Apache-2.0 License](https://opensource.org/licenses/Apache-2.0)
- `freebsd` - [FreeBSD License](https://opensource.org/licenses/BSD-2-Clause)
- `newbsd`  - [New BSD License](https://opensource.org/licenses/BSD-3-Clause)
- `gpl2`    - [GPL-3.0 License](https://opensource.org/licenses/GPL-2.0)
- `gpl3`    - [GPL-2.0 License](https://opensource.org/licenses/GPL-3.0)
- `mpl2`    - [MPL-2.0 License](https://opensource.org/licenses/MPL-2.0)
- `cddl1`   - [CDDL-1.0 License](https://opensource.org/licenses/CDDL-1.0)
- `epl1`    - [EPL-1.0 License](https://opensource.org/licenses/EPL-1.0)

### Create API
```
$ grapethor help api

Usage:
  grapethor api VERSION

Options:
  -p, [--path=PATH]            # Relative path to application directory
                               # Default: .

Creates new API within application
```
Do not forget to ```cd``` into application directory before run this command. Otherwise use ```--path``` option.

Multiple API versions may be created for single application.

### Create Resource

```
$ grapethor help resource

Usage:
  grapethor resource NAME

Options:
  -p, [--path=PATH]             # Relative path to application directory
                                # Default: .
  -v, [--version=VERSION]       # API version tag
                                # Default: v1
  -a, [--attrs=ATTRIBUTE:TYPE]  # Model attributes (use proper types or specific ORM)

Creates new Resource within API
```
Multiple RESOURCES may be created for single API version

Note: ':id' request path parameter is implicitly used as primary key. There is no need to include it with '-a' option.

Model attribute types available for specific ORM:

- activerecord: `bigint, binary, boolean, date, datetime, decimal, float, integer, numeric, string, text, time`

### Create Endpoint
```
$ grapethor help endpoint

Usage:
  grapethor endpoint RESOURCE [NAME]

Options:
  -p, [--path=PATH]         # Relative path to application directory
                            # Default: .
  -v, [--version=VERSION]   # API version tag
                            # Default: v1
  -m, [--method=METHOD]     # HTTP request method
                            # Default: GET
                            # Possible values: GET, POST, PUT, DELETE
  -d, [--desc=DESC]         # Endpoint description
  -a, [--params=key:value]  # Request resource (path) param
  -q, [--query=key:value]   # Request query params

Creates new Endpoint within API
```
Multiple ENDPOINTS may be created for single API version.

This command may be also used for an addition into existing RESOURCE CRUD.


## How-To

[Sample Workflow](https://github.com/rawongithub/grapethor/wiki/Sample-workflow)

## Development

After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/rawongithub/grapethor.


## License

The software is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).