Small application to demostrate how to use gstore-api
- Install the dependencies
npm install
- 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
- Launch the server (better with nodemon). Inside the example folder run:
NODE_ENV=development nodemon app/server.js
- 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
.
To test the API I recommend Postman but any API tool will do.
GET /api/v1/users
GET /api/v1/users/{id}
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
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
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 /api/v1/users/{id}
Delete a User at the specific id.
DELETE /api/v1/users
Delete all the users in the Datastore.
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.