Skip to content

Latest commit

 

History

History
121 lines (79 loc) · 2.8 KB

README.md

File metadata and controls

121 lines (79 loc) · 2.8 KB

gstore-api App example

Small application to demostrate how to use gstore-api

Launch the app

  1. Install the dependencies
npm install
  1. Create a file named ".env" at the root of the example folder.
    Put inside the file these 2 environment variables:
GCLOUD_PROJECT=name-of-your-project
GOOGLE_APPLICATION_CREDENTIALS=/absolute/path/to/your/credentials.json
  1. Launch the server (better with nodemon). Inside the example folder run:
NODE_ENV=development nodemon app/server.js

What does it do

  • It will generate an API to list, create, update and delete Users
  • Create an /auth/login route to log a user in

Once the server is launched you can access it at http://localhost:3007.

Test the API

To test the API I recommend Postman but any API tool will do.

List all users

GET /api/v1/users

Get a user

GET /api/v1/users/{id}

Create a user

POST /api/v1/users

Here you can either just pass a raw JSON object with the following properties (don't forget to set the "Content-type" Header to "application/json":

  • username (required)
  • password (required)
  • firstname
  • lastname
  • email

Or you can create user by uploadding a profile picture (simulated in the modules/user/user.controller.js) by setting the body type of the Request to form-data.
You can now pass a "profilePict" property of type File.

  • username (required)
  • password (required)
  • profilePict (File type)
  • firstname
  • lastname
  • email

Update a user

PATCH /api/v1/users/{id}

Modify the properties of a specific User. Like with "create" above you can either update the user by sending a raw JSON object, or also by uploading a file (through form-data fields).

Delete a user

DELETE /api/v1/users/{id}

Delete a User at the specific id.

Delete ALL users

DELETE /api/v1/users

Delete all the users in the Datastore.

User login (auth)

The demo application also shows you how you can login a user with the following route:

POST /auth/login

and by passing a JSON object in the body of the request

{
    "username": "john",
    "password": "your-password"
}

If the username and password are correct you should receive a dummy token back.