GithubHelp home page GithubHelp logo

guilhebl / nodeapi Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ealeksandrov/nodeapi

0.0 2.0 0.0 90 KB

Simple RESTful API implementation on Node.js + MongoDB.

License: MIT License

JavaScript 100.00%

nodeapi's Introduction

Node REST API

CI Status Dependency Status Dependency Status License

NodeAPI is REST API server implementation built on top Node.js and Express.js with Mongoose.js for MongoDB integration. Access control follows OAuth 2.0 spec with the help of OAuth2orize and Passport.js.

This is updated code that follows RESTful API With Node.js + MongoDB article.

Running project

Manual

You need to have Node.js and MongoDB installed.

Node setup on macOS

# Update Homebrew before installing all dependencies
brew update

# Install Node (+npm) with Homebrew
brew install node

# Install npm dependencies in project folder
npm install

MongoDB setup on macOS

# Install MongoDB with Homebrew
brew install mongodb

# Create directory for MongoDB data
mkdir -p ./data/mongo

# Run MongoDB daemon process with path to data directory
mongod --dbpath ./data/mongo

Run server

npm start
# alias for
node bin/www

Create demo data

npm run-script generate
# alias for
node generateData.js

Docker

You need to have Docker installed.

Run server

docker-compose up -d --build

Create demo data

docker exec nodeapi_node_api_1 node generateData.js

Make Requests

Create and refresh access tokens:

http POST http://localhost:1337/api/oauth/token grant_type=password client_id=android client_secret=SomeRandomCharsAndNumbers username=myapi password=abc1234
http POST http://localhost:1337/api/oauth/token grant_type=refresh_token client_id=android client_secret=SomeRandomCharsAndNumbers refresh_token=[REFRESH_TOKEN]

Create your article data:

http POST http://localhost:1337/api/articles title='New Article' author='John Doe' description='Lorem ipsum dolar sit amet' images:='[{"kind":"thumbnail", "url":"http://habrahabr.ru/images/write-topic.png"}, {"kind":"detail", "url":"http://habrahabr.ru/images/write-topic.png"}]' Authorization:'Bearer ACCESS_TOKEN'

Update your article data:

http PUT http://localhost:1337/api/articles/EXISTING_ARTICLE_ID title='Updated Article' author='Jane Doe' description='This is now updated' Authorization:'Bearer ACCESS_TOKEN'

Get your data:

http http://localhost:1337/api/users/info Authorization:'Bearer ACCESS_TOKEN'
http http://localhost:1337/api/articles Authorization:'Bearer ACCESS_TOKEN'

Tests

npm test
# alias for
node ./test/server.test.js

Modules used

Some of non-standard modules used:

Test modules:

Tools used

  • httpie - command line HTTP client

JSHint

npm install jshint -g
jshint libs/**/*.js generateData.js

Author

Created and maintained by Evgeny Aleksandrov (@ealeksandrov).

Updated by:

License

NodeAPI is available under the MIT license. See the LICENSE.md file for more info.

nodeapi's People

Contributors

ealeksandrov avatar fritz-c avatar guilhebl avatar i-am-smirnoff avatar istockjared avatar marsicdev avatar mostalt avatar yuttasakcom avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.