GithubHelp home page GithubHelp logo

message-server's Introduction

Message-server

Backend server for messaging application written in golang that allows registration of users, sending and downloading text, voice and video messages to other users. The server uses basic user authentication via tokens. User information and messages are stored in an sqlite-3 database with the passwords encrypted.

Contents

Building the docker image

docker build --tag=message-server .

Running the server

docker run -v $(pwd)/db:/server/db -p 8080:8080 message-server

Testing

Requires go 1.11 and go modules.

go test ./...

API Specification

The specification for the server is in the "swagger.json" file.

API Examples

Health check

Check the health of the system.

Example:

curl -v GET localhost:8080/check
{"health":"ok"}

Register User

Registers a new user to the message service. Requires an username that doesn't exist on the system and a non empty password. On success it returns the userId of the new user.

Example:

curl -v POST -d '{"username":"testUser", "password":"testPassword"}' localhost:8080/users
{"id":1}

Login User

Login an user to the system. Requires the user's username and password. On success it returns the userId of the user and an authorization token.

Example:

curl -v GET -d '{"username":"testUser", "password":"testPassword"}' localhost:8080/login
{"id":1,"token":"4974e5a5-c2ef-4562-be0d-54ab937b590b"}

Send Message

Sends a message from one user to another one. Requires the sender userId, the recipient userId and a message content. Requires an access token for authentication. It returns the messageId and a timestamp on success.

Example:

curl -v POST -d '{"sender":1, "recipient":2, "content":{"type":"text","text":"testMessage"}}' -H 'Authorization:Bearer 4974e5a5-c2ef-4562-be0d-54ab937b590b' localhost:8080/messages
{"id":1,"timestamp":"2019-04-12T12:52:45Z"}

Content types:

  • Text {"type":"text", "message":"someMessage"}
  • Image {"type":"image", "url":"www.example.com", "width":640, "height":480}
  • Video {"type":"video", "url":"www.example.com", "source":"youtube"}

Valid sources for video content are "youtube" and "vimeo".

Get Message

Returns the messages for an user starting from a given messageId. The number of messages can be limited by the "limit" parameter (default 100). Requires an access token for authentication.

Example:

curl -v GET -H 'Authorization:Bearer e1289aba-acf2-4b24-a5a7-8559d9831c6b' "localhost:8080/messages?id=2&start=1&limit=100"
{"messages":[{"id":1,"timestamp":"2019-04-12T12:52:45.642356449Z","sender":1,"recipient":2,"content":{"type":"text","text":"testMessage"}}]}

message-server's People

Contributors

maidaneze avatar

Stargazers

 avatar

Watchers

 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.