Developed For My CS-452 Class Assigment for WebApi Calls
Allow for easy access and usage for a backend Server Written in NodeJS
This uses a Node.js module available through the npm registry.
Before installing, download and install Node.js. Node.js 0.10 or higher is required.
Installation is done using the
npm install
command:
$ npm install express --save
- mongoose to drive mongodb (user model: https://github.com/timqian/auth-api/blob/master/src/models/User.js);
- Generate the following AUTH api for you at
http://localhost:3000
Method | URL | data(if needed) | server action(The Request is Successful) |
---|---|---|---|
GET | /api/v1/Auth | Lists The Api Structure and usage Calls | |
POST | /api/v1/Auth/CreateAccount | {name: ..., email: ..., password: ...} | Checks inputs and creates new Account |
POST | /api/v1/Auth/Login | {email: ..., password: ...} | Checks username/passwords and Generates APi Token |
GET | /api/v1/Auth/TestToken | {token(the generated Login token)} | verifies token and displays test data |
GET | /api/v1/Data | {token(the generated Login token)} | verifies token and displays Users Data |
(more details coming soon!!)
To use the API all you have to do is make an HTTP Call to the web address with the correct information Added
Example 1.) Calling in Powershell
Invoke-RestMethod -Uri http://localhost:3000/api/v1/Auth
Example 2.) Calling Basic Api Using HTTP:
http://localhost:3000/api/v1/Auth
Example 3.) Calling CreateAccount Using HTTP:
To add items to the request just append them to the url using HTTP Query
http://localhost:3000/api/v1/Auth/CreateAccount
?username=TestUsername //First Value Gets a ?
&password=TestPassword //Other Values Get a &
&email=TestEmail@captechu.edu //Other Values Get a &
The Entire Example
http://localhost:3000/api/v1/Auth/CreateAccount?username=TestUsername&password=TestPassword&email=TestEmail@email.edu
The response Will look Like this
{
"result":true,
"data":{
"username":"TestUsername",
"password":"B3HJyF69ue3HvHOO9arYBA==$1FK3trdZWx8BYvfsl1hDn9Yciu4PwBGUiVxGKFRYGN//jArcRA501rQOdPJOuZrbeIKBP30bcMYbOYNe+vpHkw==",
"email":"TestEmail@captechu.edu",
"accounttype":"",
"oauth2":{}
}
}
- better http status code
- better config params
- docs
- new features
MIT license
William Wright
wawright@captechu.edu