Skip to content
camhart edited this page Mar 12, 2015 · 7 revisions

#CRUD Endpoints

All database models have 4 endpoints (Create, Read, Update, Delete). The model 'budget' is used in the examples below, but any of the other models (transaction, envelope, profile) can be substituted. You must be logged in in order to gain access to the end points.

###CREATE

  • POST /budget
  • REQUIRES = a JSON object in request body
  • RETURNS = id of newly created object
# Example of url to post
  localhost:3000/budget

# Example of request body when creating a new budget object
{
	"name":"my first budget",
	"owners": [1],
	"participants":[1],
	"envelopes":[1,2,3,4,5],
	"frequency": "monthly"
}

###READ

  • GET /budget/:id
  • REQUIRES = id of an object as request parameter (passed in through the url)
  • RETURNS = JSON encoded object

###UPDATE

  • PUT /budget/:id
  • REQUIRES = id of an object as request parameter, and JSON object in request body (see example JSON object from CREATE)
  • RETURNS = 200 response if successful

###DELETE

  • DELETE /budget/:id
  • REQUIRES = id of an object as request parameter
  • RETURNS = 200 response if successful

Get all budgets for user

  • GET /budgets/
  • returns list of budgets (should only have 1 for now)
[
    {
        "_id": "5501eb0253682c6c1cbf62b0",
        "name": "cameron",
        "frequency": "monthly",
        "__v": 0,
        "envelopes": [],
        "participants": [
            "54ff4e2ada8ae93c119ac0ad"
        ],
        "owners": [
            "54ff4e2ada8ae93c119ac0ad"
        ]
    }
]

Get all envelopes for budget

  • GET /envelopes/:budgetId
  • returns list of envelopes
[
    {
        "_id": "54ff81ace7fec44828cdd34d",
        "budgetId": "54ff55b55b9b572c0cac3d87",
        "name": "Groceries",
        "budgetAmount": 100,
        "currentAmount": 100,
        "__v": 0
    },...
]

Get all transactions for envelope

  • GET /transactions /:envelopeId
  • returns list of transactions
[
    {
        "_id": "54ff7ad2fd8b32fc13cec3d6",
        "envelopeId": "54ff7a5ffd8b32fc13cec3d4",
        "amount": 10,
        "entity": "no clue",
        "type": "sometype",
        "__v": 0,
        "createdOn": "2015-03-10T23:14:26.971Z",
        "occuredOn": "2015-03-10T23:14:26.970Z"
    },...
]

#Other Endpoints ###REGISTER USER

  • POST /register

  • REQUIRES = json object formatted like the example below

  • RETURNS = On success, redirects to homepage. On failure, gives json encoded array of reasons for failure

    Example json register object

        {
        	"name": "Richard Dick",
        	"email" : "budgettogetrich@gmail.com",
          	"password" : "budget4lyfe",
          	"confirmPassword" : "budget4lyfe",
          	"username" : "coolest_user_ever"
        }

Example failed register response (list of json objects describing errors)

        [
            {
                "param": "email",
                "msg": "E-mail address is already in-use",
                "value": "budgettogetrich@gmail.com"
            }
        ]

###LOGIN USER

  • POST /login

  • REQUIRES = json object formatted like the example below

  • RETURNS = json user object on success (200 status code), Unauthorized on failure (401 status code)

    Example of login object

        {
        	"email" : "budgettogetrich@gmail.com",
          	"password" : "budget4lyfe"
        }

Successful response for login

        {
            "user": {
                "_id": "54dabb77b3aa32d4145238af",
                "name": "Richard Dick",
                "email": "budgettogetrich@gmail.com",
                "username": "coolest_user_ever",
                "__v": 0,
                "provider": "local",
                "roles": [
                    "authenticated"
                ]
            },
            "redirect": false
        }

###OAuths

  • GET /auth/facebook
  • GET /auth/google

Clone this wiki locally