Code Monkey home page Code Monkey logo

image-server-rest's Introduction

Image Server REST

A simple image server that uses REST APIs to register/login user and lets him/her upload images to it.

APIs

Register user

Returns json data about the registered user.

  • URL

    /register

  • Scope

    PUBLIC

  • Method:

    POST

  • URL Params

    None

  • Data Params

    email: String
    password: String

  • Success Response:

    • Code: 200
      Content:
      {
        "id": 1,
        "email": "[email protected]",
        "password": "some_password",
        "firstName": "some_name",
        "lastName": "some_last_name"
      }
      
  • Error Response:

    • Code: 400 BAD REQUEST
      Content: { "message": "Username has already been taken." }
  • Sample Call:

      curl --location --request POST 'localhost/register' \
      --form 'email=EMAIL' \
      --form 'password=PASSWORD'

Login user

Returns json data about the logged user, without password and with a webtoken.

  • URL

    /login

  • Scope

    PUBLIC

  • Method:

    POST

  • URL Params

    None

  • Data Params

    email: String
    password: String

  • Success Response:

    • Code: 200
      Content:
      {
          "id": 1,
          "email": "a",
          "firstName": "a",
          "lastName": "",
          "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEsImlhdCI6MTU5OTMxOTcyMCwiZXhwIjoxNTk5MzM3NzIwfQ.jlvpehyhoAFaeQFde_W80NwbTZktuSaK7emqUyVdDT8"
      }
      
  • Error Response:

    • Code: 400 BAD REQUEST
      Content: { "message": "Username or password is incorrect" }
  • Sample Call:

    curl --location --request POST 'localhost/login' \
    --form 'email=EMAIL' \
    --form 'password=PASSWORD'

Get all images

Returns json data about the all the images stored.

  • URL

    /images

  • Scope

    PRIVATE

  • Method:

    GET

  • URL Params

    None

  • Data Params

    None

  • Success Response:

    • Code: 200
      Content:
      [
        {"id":0,"image_name":"test.png","date":"Sat Sep 01 1963 17:25:58 GMT+0200 (Central European Summer Time)"},
        ...
        {"id":1231,"image_name":"file.png","date":"Sat Sep 02 1963 17:25:58 GMT+0200 (Central European Summer Time)"}
      ]
      
  • Sample Call:

    curl --location --request GET 'localhost/images'

Get all users

Returns json data about the all the users stored.

  • URL

    /users

  • Scope

    PRIVATE

  • Method:

    GET

  • URL Params

    None

  • Data Params

    None

  • Success Response:

    • Code: 200
      Content:
      [
        {"id":0,"email":"test","firstName":"Test","lastName":"User"},
        ...
        {"id":1213,"email":"abc","firstName":"abc","lastName":"abc"}
      ]
      
  • Sample Call:

    curl --location --request GET 'localhost/users'

Upload image

Returns json data about the uploaded image.

  • URL

    /images/uploadImage

  • Scope

    PRIVATE

  • Method:

    POST

  • URL Params

    None

  • Form Params

    image: File

  • Success Response:

    • Code: 200
      Content:
      {
        "id":1121,
        "user":4941,
        "image_name":"_g0p7akqke - image.png",
        "date":"2020-09-05T15:35:53.073Z"
      }
      
  • Sample Call:

    curl --location --request POST 'localhost/images/uploadImage' \
    --header 'Authorization: Bearer webtoken' \
    --form 'image=@/Users/example/folder/image.png'

Get image

Returns specified image if present.

  • URL

    /images/:imageId

  • Scope

    PRIVATE

  • Method:

    POST

  • URL Params

    imageId: int

  • Form Params

    None

  • Success Response:

    • Code: 200
      Content: Image
  • Error Response:

    • Code: 400 BAD REQUEST
      Content: { "message": "Image does not exist" }

    OR

    • Code: 500 INTERNAL SERVER ERROR
      Content: { "message": "Server was unable to retrieve the image." }
  • Sample Call:

    curl --location --request GET 'localhost/images/1123' \
    --header 'Authorization: Bearer webtoken'

Get images of user

Returns json data about every image that a specified user has uploaded.

  • URL

    /images/search

  • Scope

    PRIVATE

  • Method:

    POST

  • URL Params

    None

  • Form Params

    user: int

  • Success Response:

    • Code: 200
      Content:
      [
        {"id":0, "image_name":"test.png", "user":1, "date":"Sat Sep 05 2020 17:42:14 GMT+0200 (Central European Summer Time)"},
        ...
        {"id":1, "user":1, "image_name":"_4wljyxeuj - image.png", "date":"2020-09-05T15:45:49.985Z"}
      ]
      
  • Error Response:

    • Code: 400 BAD REQUEST
      Content: { "message": "No image of ${user} were found" }
  • Sample Call:

    curl --location --request GET 'localhost/images/search' \
    --header 'Authorization: Bearer webtoken' \
    --header 'Content-Type: application/x-www-form-urlencoded' \
    --data-urlencode 'user=111111'

Backend

How to start the server

Navigate to cloned repository

npm install to install the required dependencies

npm test for nodemon process intended for development process

npm start for production

image-server-rest's People

Contributors

dependabot[bot] avatar luca-conterio avatar mattrighetti avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.