Skip to content

Latest commit

 

History

History
110 lines (80 loc) · 2.2 KB

File metadata and controls

110 lines (80 loc) · 2.2 KB

Super Workshop JS ⚙️ Test with cURL


Sign up for a new account

Request:

# Sign up via x-www-form-urlencoded
curl localhost:3000/auth/signup -X POST -d "email=apollo@apollo.com&name=Apollo&username=apollo&password=apollo"

# Sign up via JSON
curl localhost:3000/auth/signup \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{
    "email": "apollo@apollo.com",
    "name": "Apollo",
    "username": "apollo",
    "password": "apollo"
  }'

Response:

{"token":"ey123456789.eyABCDEFGHIJKLMNOPQRSTUVWXYZ.ABC-XYZ"}%

Sign in with existed account

Request:

# apollo
curl localhost:3000/auth/signin -X POST -d "username=apollo&password=apollo"

Response:

{"token":"ey123456789.eyABCDEFGHIJKLMNOPQRSTUVWXYZ.ABC-XYZ"}%

Check authentication

Request:

  1. req.body: /auth/is-authenticated -d "token=JWT_TOKEN"
  2. req.query: /auth/is-authenticated?token=JWT_TOKEN
  3. req.headers: Authorization: Bearer JWT_TOKEN
export TOKEN=ey123456789.eyABCDEFGHIJKLMNOPQRSTUVWXYZ.ABC-XYZ

# Body
curl http://localhost:3000/auth/is-authenticated -d "token=$TOKEN" -X POST

# Query
curl "http://localhost:3000/auth/is-authenticated?token=$TOKEN" -X POST

# Header
curl localhost:3000/auth/is-authenticated -X POST -H "Authorization: Bearer $TOKEN" -X POST

Response:

true

NOTE: Use this only for checking.


Post a new book

Request:

curl localhost:3000/api/books \
  -X POST \
  -H 'Authorization: Bearer ey123456789.eyABCDEFGHIJKLMNOPQRSTUVWXYZ.ABC-XYZ' \
  -H 'Content-Type: application/json' \
  -d '{
    "isbn": "121212",
    "name": "Twelve",
    "price": 12
  }'

Response:

{
  "__v": 0,
  "_id": "582c55169b62473608c0237e",
  "updatedAt": "2016-11-16T12:46:14.812Z",
  "createdAt": "2016-11-16T12:46:14.812Z",
  "isbn": "121212",
  "name": "Twelve",
  "price": 12,
  "owners": []
}