Skip to content

Commit 69b9a79

Browse files
Fadojutimi Temitayo Olusegunadesege
Fadojutimi Temitayo Olusegun
authored andcommitted
release v1.0.0
0 parents  commit 69b9a79

File tree

19 files changed

+6244
-0
lines changed

19 files changed

+6244
-0
lines changed

.babelrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"presets": [
3+
"env"
4+
]
5+
}

.coveralls.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
repo_token: COVERALLS_REPO_TOKEN

.eslintrc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"root": true,
3+
"extends": [ "airbnb-base" ],
4+
"env": {
5+
"node": true,
6+
"es6": true,
7+
"mocha": true
8+
},
9+
"rules": {
10+
"global-require":0,
11+
"import/no-dynamic-require":0,
12+
"one-var": 0,
13+
"one-var-declaration-per-line": 0,
14+
"new-cap": 0,
15+
"consistent-return": 0,
16+
"no-param-reassign": 0,
17+
"comma-dangle": 0,
18+
"curly": ["error", "multi-line"],
19+
"import/no-unresolved": [2, { "commonjs": true }],
20+
"no-shadow": ["error", { "allow": ["req", "res", "err"] }],
21+
"valid-jsdoc": ["error", {
22+
"requireReturn": true,
23+
"requireReturnType": true,
24+
"requireParamDescription": false,
25+
"requireReturnDescription": true
26+
}],
27+
"require-jsdoc": ["error", {
28+
"require": {
29+
"FunctionDeclaration": true,
30+
"MethodDefinition": true,
31+
"ClassDeclaration": true
32+
}
33+
}]
34+
}
35+
}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules/
2+
build/
3+
.nyc_output/
4+
coverage/

.travis.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
env:
2+
global:
3+
- CC_TEST_REPORTER_ID=$CODECLIMATE_REPO_TOKEN
4+
- GIT_COMMITTED_AT=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then git log -1 --pretty=format:%ct; else git log -1 --skip 1 --pretty=format:%ct; fi)
5+
language: node_js
6+
before_script:
7+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
8+
- chmod +x ./cc-test-reporter
9+
script:
10+
- bundle exec rspec
11+
# Preferably you will run test-reporter on branch update events. But
12+
# if you setup travis to build PR updates only, you don't need to run
13+
# the line below
14+
- if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT; fi
15+
# In the case where travis is setup to build PR updates only,
16+
# uncomment the line below
17+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
18+
node_js:
19+
- node
20+
notifications:
21+
email: false
22+
before_script:
23+
- npm install -g codeclimate-test-reporter
24+
- npm install -g coveralls
25+
- npm install -g sequelize
26+
script:
27+
- npm test
28+
after_success:
29+
- npm run coveralls
30+
- codeclimate-test-reporter < coverage/lcov.info
31+
- coveralls < coverage/lcov.info

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
(The MIT License)
2+
3+
Copyright (c) 2017 Fadojutimi Temitayo Olusegun <[email protected]>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining
6+
a copy of this software and associated documentation files (the
7+
'Software'), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Readme.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
[![Build Status](https://travis-ci.org/adesege/express-api-versioning.svg)](https://travis-ci.org/adesege/express-api-versioning)
2+
[![Coverage Status](https://coveralls.io/repos/github/adesege/express-api-versioning/badge.svg)](https://coveralls.io/github/adesege/express-api-versioning)
3+
[![Code Climate](https://codeclimate.com/github/adesege/express-api-versioning/badges/gpa.svg)](https://codeclimate.com/github/adesege/express-api-versioning)
4+
[![Test Coverage](https://codeclimate.com/github/adesege/express-api-versioning/badges/coverage.svg)](https://codeclimate.com/github/adesege/express-api-versioning/coverage)
5+
[![Issue Count](https://codeclimate.com/github/adesege/express-api-versioning/badges/issue_count.svg)](https://codeclimate.com/github/adesege/express-api-versioning)
6+
7+
# Express API Versioning
8+
9+
Express API versioning is an express middleware that dynamically loads different API versions seamlessly depending on the version number specified in the request url.
10+
11+
It is written in Javascript ES6 syntax and it is further transpiled down to Javascript ES5 using babel.
12+
13+
# Installation
14+
15+
- `npm install express-api-versioning --save`
16+
- `express` is required as a peer dependency.
17+
18+
# Usage
19+
20+
### Using ES6
21+
22+
` import expressApiVersioning from 'express-api-versioning';`
23+
### Using ES5
24+
25+
` const expressApiVersioning = require('express-api-versioning');`
26+
### Basic Usage
27+
28+
```js
29+
app.use(expressApiVersioning({
30+
instance: app, // passes an instance of express to the entry point
31+
apiPath: path.join(__dirname, './api'), // absolute path to the api directory
32+
test: /\/api\/(v[0-9]+)[a-z0-9/_+-]*/, // regular expression to get the version number from the url
33+
entryPoint: 'app.js' // entry point exports a function which takes an instance of express as parameter.
34+
}));
35+
```
36+
### Advanced Usage
37+
38+
```js
39+
app.use(expressApiVersioning({
40+
instance: app, // passes an instance of express to the entry point
41+
apiPath: path.join(__dirname, './api'), // absolute path to the api directory
42+
test: /\/endpoint\/(v[0-9]+)[a-z0-9/_+-]*/, // regular expression to get the version number from the url,
43+
entryPoint: 'index.js' // entry point exports a function which takes an instance of express as parameter.
44+
}));
45+
```
46+
- Check the [src/example](/src/sample) directory to understand the folder structure.
47+
48+
# Error Handling
49+
50+
The middleware will throw an exception when;
51+
1. the `apiPath` is not specified
52+
1. an express `instance` is not specified and not a function
53+
1. the api version cannot be found in the `api directory`.
54+
55+
# Issue Reporting
56+
57+
Please use the [issues](/issues) page to report an issue.
58+
59+
# API References
60+
61+
`Express API Versioning` is highly customizable and does not introduce complexities to your application folder structure. It takes a configuration object as parameter.
62+
63+
| Configuration item | Default | Description |
64+
| ------ | ------ | ------- |
65+
| test | /\/api\/(v[0-9]+)[a-z0-9/_+-]*/ | Regular expression to get the version number from the request url. It gets the version number from the first group of the regex match.
66+
| entryPoint | app.js | Entry point for each api version. It exports a function which takes an instance of express as parameter.
67+
| apiPath | empty string | Absolute path to each api version container/directory. This is usually `path.join(__dirname, './api')`.
68+
| instance | null | An instance of express app which will be passed down to the entry point for usage.
69+
70+
# Todo
71+
72+
- Create a boilerplate for `Express API Versioning` with `Sequelize` as ORM
73+
74+
# Author
75+
76+
**Temitayo Fadojutimi** is a Software Developer at Andela and he dedicates his expertise to solving practical problems in the society. He tweets at [@adesege_](http://twitter.com/adesege_)
77+
78+
# Testing
79+
80+
If you will like to test this package,
81+
- Clone this repo or `npm install express-api-versioning`
82+
- cd into the package directory and run `npm install`
83+
- Then run `npm test` to run the test.
84+
85+
# Contributing
86+
87+
Thank you for your interest in contributing to this package. I currently accept contributions from everyone but I expect that standards are maintained.
88+
To contribute,
89+
1. Fork the project
90+
1. Create a feature branch, branch away from `master`
91+
1. Write tests, using `Mocha and Chai` or any other testing frameworks, and code
92+
1. If you have multiple commits please combine them into a few logically organized commits by [squashing them](git-squash)
93+
1. Push the commit(s) to your fork
94+
1. Submit a merge request (MR) to the `master` branch
95+
1. The MR title should describe the change you want to make
96+
1. The MR description should give a motive for your change and the method you used to achieve it.
97+
1. Mention the issue(s) your merge request solves, using the `Solves #XXX` or
98+
`Closes #XXX` syntax to auto-close the issue(s) once the merge request will
99+
be merged.
100+
1. Be prepared to answer questions and incorporate feedback even if requests for this arrive weeks or months after your MR submission
101+
1. If a discussion has been addressed, select the "Resolve discussion" button beneath it to mark it resolved.
102+
1. When writing commit messages please follow
103+
[these guidelines](http://chris.beams.io/posts/git-commit).

0 commit comments

Comments
 (0)