PROJECT

TrainingBuddy API

The API implementation for TrainingBuddy APP

**INSTALL FLOWCHART USAGE Database AUTHOR CONTRIBUTE LICENSE SUPPORT**

MOTIVATION

This private repository is used to develope the back-end API for the TrainingBudday APP.

GETTING STARTED

The codes have been migrated from Heroku to DigitalOcean, and can be accessed through the HTTP address:

http://159.203.33.255:3000, where 3000 is the default port number for this API.

In the following usage guide, the keyword url will be referred to this HTTP address. Currently there are three models implemented in this back-end development:

All models support CRUB operations with Express and MongoDB. The difference between users and facebookusers is the field of password, since facebook login does not need users’ passwords.

Routes about users:

Routes about facebookusers:

Routes about tb_events:

Routes about some other features:

Public routes can be invokded without tokens, while private ones require tokens to execute the operations. Therefore, users can check the tb_events created by other users, but they can only delete and update their own tb_events. All tb_events will be created with users’ token as one of the key value.

Regarding the security of users’ data, all passwords that users provided will be hashed before being stored in our database. In current stage, the authentication only allows new users to sign up with their email/password. There are some other tasks are on-going for TrainingBuddy APP.

INSTALLATION

All the required libraries can be found in package.json.

npm install

FLOWCHART

Optional Text

USAGE

var http = require("http");

var options = {
  "method": "POST",
  "hostname": [
    "159.203.33.255:3000"
  ],
  "path": [
    "users"
  ],
  "headers": {
    "Content-Type": "application/json"
  }
};

var req = http.request(options, function (res) {
  var chunks = [];

  res.on("data", function (chunk) {
    chunks.push(chunk);
  });

  res.on("end", function () {
    var body = Buffer.concat(chunks);
    console.log(body.toString());
  });
});

req.write(JSON.stringify({ email: 'chao0716_8@gmail.com', password: 'test123' }));
req.end();
var http = require("http");

var options = {
  "method": "GET",
  "hostname": [
    "159.203.33.255:3000"
  ],
  "path": [
    "users",
    "me"
  ],
  "headers": {
    "x-auth": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1YTg4YmFmMDc3Yzk1YTY5OGI5ZjFhNWYiLCJhY2Nlc3MiOiJhdXRoIiwiaWF0IjoxNTE4OTExNjA5fQ.KCYOqMQu4jLCWnGkWahxegpJ-0UZt6q-LCtURPKquak"
  }
};

var req = http.request(options, function (res) {
  var chunks = [];

  res.on("data", function (chunk) {
    chunks.push(chunk);
  });

  res.on("end", function () {
    var body = Buffer.concat(chunks);
    console.log(body.toString());
  });
});

req.end();
var http = require("http");

var options = {
  "method": "DELETE",
  "hostname": [
    "159.203.33.255:3000"
  ],
  "path": [
    "users",
    "me",
    "token"
  ],
  "headers": {
    "x-auth": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1YTg4YmFmMDc3Yzk1YTY5OGI5ZjFhNWYiLCJhY2Nlc3MiOiJhdXRoIiwiaWF0IjoxNTE4OTExNjA5fQ.KCYOqMQu4jLCWnGkWahxegpJ-0UZt6q-LCtURPKquak"
  }
};

var req = http.request(options, function (res) {
  var chunks = [];

  res.on("data", function (chunk) {
    chunks.push(chunk);
  });

  res.on("end", function () {
    var body = Buffer.concat(chunks);
    console.log(body.toString());
  });
});

req.end();
var http = require("http");

var options = {
  "method": "POST",
  "hostname": [
    "159.203.33.255:3000"
  ],
  "path": [
    "users",
    "login"
  ],
  "headers": {
    "Content-Type": "application/json"
  }
};

var req = http.request(options, function (res) {
  var chunks = [];

  res.on("data", function (chunk) {
    chunks.push(chunk);
  });

  res.on("end", function () {
    var body = Buffer.concat(chunks);
    console.log(body.toString());
  });
});

req.write(JSON.stringify({ email: 'chao0716_111@gmail.com', password: 'test123' }));
req.end();
var http = require("http");

var options = {
  "method": "PATCH",
  "hostname": [
    ""
  ],
  "path": [
    "users",
    "profile",
    ""
  ],
  "headers": {
    "Content-Type": "application/json",
    "x-auth": ""
  }
};

var req = http.request(options, function (res) {
  var chunks = [];

  res.on("data", function (chunk) {
    chunks.push(chunk);
  });

  res.on("end", function () {
    var body = Buffer.concat(chunks);
    console.log(body.toString());
  });
});

req.write(JSON.stringify({ gender: 'female',
  name:
   [ { firstName: 'Catherine',
       middleName: 'MiddleName',
       lastName: 'Kate',
       userName: 'CK' } ],
  address:
   [ { street: 'Monkland 4410',
       city: 'Montreal',
       province: 'Quebec',
       state: 'NA',
       country: 'Canada',
       postCode: 'H4B 2S9' } ],
  title: 'Mrs.',
  birthOfDate: [ { year: '1971', month: 'Jan', date: '10' } ],
  phone: '514-872-8588',
  occupation: 'Trainer',
  rate: 4 }));
req.end();
var http = require("http");

var options = {
  "method": "DELETE",
  "hostname": [
    ""
  ],
  "path": [
    "users",
    "facebook",
    "logout"
  ],
  "headers": {
    "x-auth": "EAAIFJPAxW3wBAK2cMBj7VrzZAJrPDyij547w9KXe2VHl6uzjRXXyV5m0svVgDvPtn7Nb20zKMlfZBZAbDRwtEZBDxOZBrhZAlomHJ7Llj9aU0IWKfepAbOM9ipw6ObIF5bMRq3aSZB5vgdVDTQakBbTSdbrOxDnEIPkosdE5d0pqnAeb8f3ke3T"
  }
};

var req = http.request(options, function (res) {
  var chunks = [];

  res.on("data", function (chunk) {
    chunks.push(chunk);
  });

  res.on("end", function () {
    var body = Buffer.concat(chunks);
    console.log(body.toString());
  });
});

req.end();
var http = require("http");

var options = {
  "method": "POST",
  "hostname": [
    "159.203.33.255:3000"
  ],
  "path": [
    "tb_events"
  ],
  "headers": {
    "Content-Type": "application/json",
    "x-auth": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1YTg4YmFmMDc3Yzk1YTY5OGI5ZjFhNWYiLCJhY2Nlc3MiOiJhdXRoIiwiaWF0IjoxNTE4OTExNjA5fQ.KCYOqMQu4jLCWnGkWahxegpJ-0UZt6q-LCtURPKquak"
  }
};

var req = http.request(options, function (res) {
  var chunks = [];

  res.on("data", function (chunk) {
    chunks.push(chunk);
  });

  res.on("end", function () {
    var body = Buffer.concat(chunks);
    console.log(body.toString());
  });
});

req.write(JSON.stringify({ name: 'Body Building',
  activityPicked: 'Training',
  date: [ { dateFrom: '2018-02-01', dateTo: '2018-03-01' } ],
  place: [ { geo_lat: 20, geo_lng: 50 } ],
  age_suggest: [ { start: 18, end: 50 } ],
  num_people: 80,
  time_duration: [ { time: '02:00:00', timeFrom: '18:00:00', timeTo: '20:00:00' } ],
  level: 'beginner',
  description: [ { comments: 'For muscles', rating: 4.7 } ] }));
req.end();
var http = require("http");

var options = {
  "method": "GET",
  "hostname": [
    "159.203.33.255:3000"
  ],
  "path": [
    "tb_events",
    ""
  ],
  "headers": {}
};

var req = http.request(options, function (res) {
  var chunks = [];

  res.on("data", function (chunk) {
    chunks.push(chunk);
  });

  res.on("end", function () {
    var body = Buffer.concat(chunks);
    console.log(body.toString());
  });
});

req.end();
var http = require("http");

var options = {
 "method": "GET",
 "hostname": [
   "159.203.33.255:3000"
 ],
 "path": [
   "tb_events",
   "users",
   "5a88b9f277c95a698b9f1a50"
 ],
 "headers": {
   "x-auth": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1YTg4YmFmMDc3Yzk1YTY5OGI5ZjFhNWYiLCJhY2Nlc3MiOiJhdXRoIiwiaWF0IjoxNTE4OTExNjA5fQ.KCYOqMQu4jLCWnGkWahxegpJ-0UZt6q-LCtURPKquak"
 }
};

var req = http.request(options, function (res) {
 var chunks = [];

 res.on("data", function (chunk) {
   chunks.push(chunk);
 });

 res.on("end", function () {
   var body = Buffer.concat(chunks);
   console.log(body.toString());
 });
});

req.end();
var http = require("http");

var options = {
 "method": "DELETE",
 "hostname": [
   "159.203.33.255:3000"
 ],
 "path": [
   "tb_events",
   "5a88bd9177c95a698b9f1a78"
 ],
 "headers": {
   "x-auth": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1YTg4YmFmMDc3Yzk1YTY5OGI5ZjFhNWYiLCJhY2Nlc3MiOiJhdXRoIiwiaWF0IjoxNTE4OTExNjA5fQ.KCYOqMQu4jLCWnGkWahxegpJ-0UZt6q-LCtURPKquak"
 }
};

var req = http.request(options, function (res) {
 var chunks = [];

 res.on("data", function (chunk) {
   chunks.push(chunk);
 });

 res.on("end", function () {
   var body = Buffer.concat(chunks);
   console.log(body.toString());
 });
});

req.end();
var http = require("http");

var options = {
  "method": "PATCH",
  "hostname": [
    "159.203.33.255:3000"
  ],
  "path": [
    "tb_events",
    "join",
    "5aa70bbb58b72c16c45a8a7c"
  ],
  "headers": {
    "Content-Type": "application/json",
    "x-auth": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1YTk2ZDk4NWQxNDA5NzZhZWMwN2I1ODAiLCJhY2Nlc3MiOiJhdXRoIiwiaWF0IjoxNTIxNDg0OTE2fQ.tOKSZeZfBwTqSr7DraULBahPlB9gNAtCpKFLWgVXqB4"
  }
};

var req = http.request(options, function (res) {
  var chunks = [];

  res.on("data", function (chunk) {
    chunks.push(chunk);
  });

  res.on("end", function () {
    var body = Buffer.concat(chunks);
    console.log(body.toString());
  });
});

req.write(JSON.stringify({ gender: 'female',
  name: 
   [ { firstName: 'Catherine',
       middleName: 'MiddleName',
       lastName: 'Kate',
       userName: 'CK' } ],
  address: 
   [ { street: 'Monkland 4410',
       city: 'Montreal',
       province: 'Quebec',
       state: 'NA',
       country: 'Canada',
       postCode: 'H4B 2S9' } ],
  title: 'Mrs.',
  birthOfDate: [ { year: '1971', month: 'Jan', date: '10' } ],
  phone: '514-872-8588',
  occupation: 'Trainer',
  rate: 4 }));
req.end();
var http = require("http");

var options = {
  "method": "PATCH",
  "hostname": [
    "159.203.33.255:3000"
  ],
  "path": [
    "tb_events",
    "drop",
    "5aa70bbb58b72c16c45a8a7c"
  ],
  "headers": {
    "Content-Type": "application/json",
    "x-auth": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1YTk2ZDk4NWQxNDA5NzZhZWMwN2I1ODAiLCJhY2Nlc3MiOiJhdXRoIiwiaWF0IjoxNTIxNDg0OTE2fQ.tOKSZeZfBwTqSr7DraULBahPlB9gNAtCpKFLWgVXqB4"
  }
};

var req = http.request(options, function (res) {
  var chunks = [];

  res.on("data", function (chunk) {
    chunks.push(chunk);
  });

  res.on("end", function () {
    var body = Buffer.concat(chunks);
    console.log(body.toString());
  });
});

req.write(JSON.stringify({ gender: 'female',
  name: 
   [ { firstName: 'Catherine',
       middleName: 'MiddleName',
       lastName: 'Kate',
       userName: 'CK' } ],
  address: 
   [ { street: 'Monkland 4410',
       city: 'Montreal',
       province: 'Quebec',
       state: 'NA',
       country: 'Canada',
       postCode: 'H4B 2S9' } ],
  title: 'Mrs.',
  birthOfDate: [ { year: '1971', month: 'Jan', date: '10' } ],
  phone: '514-872-8588',
  occupation: 'Trainer',
  rate: 4 }));
req.end();
var http = require("http");

var options = {
  "method": "GET",
  "hostname": [
    "159.203.33.255:3000"
  ],
  "path": [
    "chats",
    "5aa576547ee1da097beb76b0"
  ],
  "headers": {
    "Content-Type": "application/json",
    "x-auth": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1YTk2ZDk4NWQxNDA5NzZhZWMwN2I1ODAiLCJhY2Nlc3MiOiJhdXRoIiwiaWF0IjoxNTIxNDg0OTE2fQ.tOKSZeZfBwTqSr7DraULBahPlB9gNAtCpKFLWgVXqB4"
  }
};

var req = http.request(options, function (res) {
  var chunks = [];

  res.on("data", function (chunk) {
    chunks.push(chunk);
  });

  res.on("end", function () {
    var body = Buffer.concat(chunks);
    console.log(body.toString());
  });
});

req.end();
var http = require("http");

var options = {
  "method": "GET",
  "hostname": [
    "159.203.33.255:3000"
  ],
  "path": [
    "api",
    "images",
    "upload"
  ],
  "headers": {
    "x-auth": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1YTk2ZDk4NWQxNDA5NzZhZWMwN2I1ODAiLCJhY2Nlc3MiOiJhdXRoIiwiaWF0IjoxNTIxNDg0OTE2fQ.tOKSZeZfBwTqSr7DraULBahPlB9gNAtCpKFLWgVXqB4"
  }
};

var req = http.request(options, function (res) {
  var chunks = [];

  res.on("data", function (chunk) {
    chunks.push(chunk);
  });

  res.on("end", function () {
    var body = Buffer.concat(chunks);
    console.log(body.toString());
  });
});

req.end();

All the requests can also be found in POSTMAN Documentation. In addition, a test file has been uploaded to run self-test, which will be helpful about how to send reqeusts and fetch responses through this API.

Database

The database employed in this back-end API is installed in DigitalOcean, a platform of Database-as-a-Service for MongoDB.

AUTHOR

You can just email me.

ACKNOWLEDGMENTS

List of people and project that inspired creation of this one:

CONTRIBUTION & LICENSE

Check out (if any) contribution guide or license for more details.

PRODUCTION STATUS & SUPPORT

You should be aware that this project is supported solely by me and provided as is.
If you want to become a patron or offer me a support please follow here.


Go back to the project description

Copyright © 2017 Davronov Alexander