GithubHelp home page GithubHelp logo

messageservice's Introduction

Message Service

This service exposes a RESTful API that works as a basic message store.

Configure .env

Navigate to the file .env_example in the folder src > main > resources.

Make a copy of this file and name the new file .env.

Start the server

Docker

Simply run:

make docker-run

To attach to the Docker container run:

make docker-run-attach

API

JWT is used for authentication method and a user can obtain a token by calling the Create Token endpoint. The returned token should be used in other endpoints that require authentication, so make sure you add the obtained token to the Authorization header of the request and in the following format:

Bearer {token}.

Overview

Name Method Path
Create User POST /api/v1/users
Create Token POST /api/v1/users/:user_id/tokens
Create Message POST /api/v1/users/:user_id/messages
Update Message PUT /api/v1/users/:user_id/messages/:message_id
Delete Message DELETE /api/v1/users/:user_id/messages/:message_id
Fetch All Messages GET /api/v1/messages

Create User

This endpoint creates a user.

Method:
	POST 
Path:
	/api/v1/users
Headers:
	- Content-Type: application/json
Body:
	{
	  "name": string
	}
Body Example:
	{
	  "name": "Kalle Karlsson"
	}
Success Response:
	{
	  "id": "b5eb1e6a-25ed-49f1-82c8-4cb9ff1e40b7",
	  "name": "Kalle Karlsson"
	}

Create Token

This endpoint creates a token for a certain user. The token is required for other endpoints to authenticate the user.

Method:
	POST 
Path:
	/api/v1/users/:user_id/tokens
Path Parameters:
	- user_id: Id of the user
Headers:
	- Content-Type: application/json
Body:
	{}
Success Response:
	{
	  "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ...",
	}

Create Message

This endpoint creates a message.

The created_at.timestamp field should be seconds since epoch.

The created_at.offset field should be seconds offset from UTC. For example in Sweden during daylight-saving time the value would be 7200.

Method:
	POST 
Path:
	/api/v1/users/:user_id/messages
Path Parameters:
	- user_id: Id of the user
Headers:
	- Content-Type: application/json
	- Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ... 
Body:
	{
	  "text": string,
	  "created_at": {
	    "timestamp": int,
	    "offset": int		 
	  }
	}
Body Example:
	{
	  "text": "Example text",
	  "created_at": {
	    "timestamp": 1535738112,
	    "offset": 7200
	   }
	}
Success Response:
	{
	  "id": "56f376c6-42b6-42b6-8afc-5675fca5f02a"
	  "text": "Example text",
	  "created_at": {
	    "timestamp": 1535738112,
	    "offset": 7200
	  },
	  "user": {
	    "id": "b5eb1e6a-25ed-49f1-82c8-4cb9ff1e40b7",
	    "name": "Kalle Karlsson"
	  }
	}

Update Message

This endpoint updates a message.

The created_at.timestamp field should be seconds since epoch.

The created_at.offset field should be seconds offset from UTC. For example in Sweden during daylight-saving time the value would be 7200.

Method:
	PUT
Path:
	/api/v1/users/:user_id/messages/:message_id
Path Parameters:
	- user_id: Id of the user
	- message_id: Id of the message
Headers:
	- Content-Type: application/json
	- Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ... 
Body:
	{
	  "text": string,
	  "created_at": {
	    "timestamp": int,
	    "offset": int		 
	  }
	}
Body Example:
	{
	  "text": "Updated example text",
	  "created_at": {
	    "timestamp": 1535739872,
	    "offset": 7200
	  }
	}
Success Response:
	{
	  "id": "56f376c6-42b6-42b6-8afc-5675fca5f02a"
	  "text": "Updated example text",
	  "created_at": {
	    "timestamp": 1535739872,
	    "offset": 7200
	  },
	  "user": {
	    "id": "b5eb1e6a-25ed-49f1-82c8-4cb9ff1e40b7",
	    "name": "Kalle Karlsson"
	  }
	}

Delete Message

This endpoint deletes a message.

Method:
	DELETE
Path:
	/api/v1/users/:user_id/messages/:message_id
Path Parameters:
	- user_id: Id of the user
	- message_id: Id of the message
Headers:
	- Content-Type: application/json
	- Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ... 

Fetch All Messages

This endpoint returns all messages.

Method:
	GET
Path:
	/api/v1/messages
Headers:
	- Content-Type: application/json 
Success Response:
    {
      "messages": [
        {
          "id": "56f376c6-42b6-42b6-8afc-5675fca5f02a"
          "text": "Example text from Kalle",
          "created_at": {
            "timestamp": 1535739872,
            "offset": 7200
          },
          "user": {
            "id": "b5eb1e6a-25ed-49f1-82c8-4cb9ff1e40b7",
            "name": "Kalle Karlsson"
          }
        },
        {
          "id": "7b49b316-e8cc-46ac-be95-9055cd371dc8"
          "text": "Example text from Olle",
          "created_at": {
            "timestamp": 15357456172,
            "offset": 7200
          },
          "user": {
            "id": "3b62c987-506a-4aca-909b-9ed227ea9c48",
            "name": "Olle Andersson"
          }
        }
      ]
    }

messageservice's People

Contributors

mattiaspernhult 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.