This project provide the backend functionality for the chat. It will get requests from client-side and will generate data in response. Consists in three main parts: Users, Chat Room and Message.
bundle install
rails s
rake db:migration
rake db:seed
rspec spec
Notice before run the app or tests you must have redis server running first (redis-server
).
curl http://localhost:3000/users
curl http://localhost:3000/users?ids=1,3,5
curl http://localhost:3000/users/1
This is use for asyncronous search of users. In case it doesn't find any user will return empty array []
.
curl http://localhost:3000/users/search?name=admin&[email protected]
This is use to search an user that is suppose to exists. If it doesn't find any will throw an exception.
http://localhost:3000/users/fetch?name=admin&[email protected]
curl -i -X POST -H "Content-Type:application/json" http://localhost:3000/users -d '{"name": "test", "email": "[email protected]"}'
curl -i -X PUT -H "Content-Type:application/json" http://localhost:3000/users/1 -d '{"name": "test2", "email": "[email protected]"}'
curl -i -X DELETE http://localhost:3000/users/1
curl http://localhost:3000/chat_rooms
curl http://localhost:3000/chat_rooms/1
This is use for asyncronous search of users. In case it doesn't find any user will return empty array []
.
curl http://localhost:3000/chat_rooms/search?title=Sport
curl -i -X POST -H "Content-Type:application/json" http://localhost:3000/chat_rooms -d '{"title": "games", "created_id": 1, "sender_id": 1, "recipient_id": 1}'
curl -i -X PUT -H "Content-Type:application/json" http://localhost:3000/chat_rooms/1 -d '{"title": "games", "created_id": 1, "sender_id": 1, "recipient_id": 1}'
curl -i -X DELETE http://localhost:3000/chat_rooms/1
http://localhost:3000/chat_rooms/1/messages
http://localhost:3000/chat_rooms/1/messages/2
curl -i -X POST -H "Content-Type:application/json" http://localhost:3000/chat_rooms/1/messages -d '{"body": "very long text", "user_id": 1}'
curl -i -X PUT -H "Content-Type:application/json" http://localhost:3000/chat_rooms/1/messages/1 -d '{"body": "very long text", "user_id": 1}'
curl -i -X DELETE http://localhost:3000/chat_rooms/1/messages/1
https://gmunumel-chat-rails-api-server.herokuapp.com
Licensed under MIT
Based on the following tutorials:
- Models: https://www.sitepoint.com/create-a-chat-app-with-rails-5-actioncable-and-devise/
- Models - Routing: https://github.com/nerdyfactory/react-native-chat
Redis:
- Config: http://www.victorareba.com/tutorials/speed-your-rails-app-with-model-caching-using-redis
- General Idea: https://medium.com/wolox-driving-innovation/adding-a-realtime-module-to-your-rails-api-18bb562e6441
Postgres: