项目作者: maikeulb

项目描述 :
Restful API backend for a social network application
高级语言: Go
项目地址: git://github.com/maikeulb/friend-meet-friend.git
创建时间: 2018-03-26T00:14:35Z
项目社区:https://github.com/maikeulb/friend-meet-friend

开源协议:

下载


Friend Meet Friend

Restful API backend for friend meeting application written in Go with
token-based authentication system (using JWTs). The API is written with minimal
dependencies (The only external dependencies are the router and jwt-go).

Technology

  • Go
  • PostgreSQL

Endpoints

Users

Method URI Action
GET /api/users Retrieve all user profiles
GET /api/users/{uid} Retrieve user profile
PATCH /api/users/{uid Partially update logged in user's profile
GET /api/users/{uid}/messages/{id} Retrieve user message
GET /api/users/{uid}/messages/sent Retrieve user's sent messages
GET /api/users/{uid}/messages/recieved Retrieve user's recieved messages
POST /api/users/{uid}/messages Send message to another user
POST /api/users/{uid}/follow Follow user
POST /api/users/{uid}/unfollow Unfollow user

Auth

Method URI Action
GET /auth/status Check Login Status
POST /auth/login Login User
POST /auth/register Register User

Sample Usage

http post localhost:5000/auth/register email=user@email.com username=user password=pass

  1. {
  2. "email": "user@email.com",
  3. "id": 5,
  4. "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImRlbW9AZW1haWwuY29tIiwiZXhwIjoxNTIyNzQ3NTA1LCJ1c2VySWQiOjV9.jIcIwq8hA1uSLDFyuytr1lGwQ9WNnvkubzz0qrPN7SQ"
  5. }

http post localhost:5000/auth/login email=user@email.com password=pass

  1. {
  2. "email": "user@email.com",
  3. "id": 5,
  4. "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImRlbW9AZW1haWwuY29tIiwiZXhwIjoxNTIyNzQ3NjIxLCJ1c2VySWQiOjV9.M71uY55Za_PjUo4QdZIf3FI-t6mB9ySCMuzWql1BCsE"
  5. }

http localhost:5000/api/users

  1. [
  2. {
  3. "borough": "manhattan",
  4. "createdOn": "2018-03-31T00:39:49.243078Z",
  5. "followees": [
  6. {
  7. "id": 1,
  8. "name": "michael"
  9. }
  10. ],
  11. "followers": [
  12. {
  13. "id": 4,
  14. "name": "amanda"
  15. },
  16. {
  17. "id": 1,
  18. "name": "michael"
  19. }
  20. ],
  21. "id": 2,
  22. "interests": "bmx bikes",
  23. "lastActive": "2018-03-31T00:39:49.243078Z",
  24. "name": "mick"
  25. },
  26. ...

http --auth-type=jwt --auth="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImRlbW9AZW1haWwuY29tIiwiZXhwIjoxNTIyNzQ3NjIxLCJ1c2VySWQiOjV9.M71uY55Za_PjUo4QdZIf3FI-t6mB9ySCMuzWql1BCsE" post localhost:5000/api/users/5/messages recipientId:=3 body="hey, let me know if you want to go to an art museum sometime."

  1. {
  2. "body": "hey, let me know if you want to go to an art museum sometime.",
  3. "recipient": {},
  4. "recipientId": 3,
  5. "sender": {},
  6. "senderId": 5,
  7. "timestamp": "2018-04-03T00:34:13.920188005-04:00"
  8. }

Run

With docker:

  1. docker-compose build
  2. docker-compose up -d db
  3. docker-compose up
  4. Go to http://localhost:5000 and visit one of the above endpoints

Alternatively, create a database named ‘friendmeetfriend’, run the migration
scripts (located in the ./migrations/), and then open main.go and point the PostgreSQL URI to your server.

cd into ./friend-meet-friend (if you are not already); then run:

  1. go build
  2. ./friend-meet-friend
  3. Go to http://localhost:5000 and visit one of the above endpoints

TODO

Update last active timestamp upon user login
Add unit tests
Add an eloquent config management package
Add CORS
Consider removing token after registration