https://github.com/minikin/twitter-rs
Simple Twitter API Clone in Rust.
https://github.com/minikin/twitter-rs
postgresql rust twitter
Last synced: 3 months ago
JSON representation
Simple Twitter API Clone in Rust.
- Host: GitHub
- URL: https://github.com/minikin/twitter-rs
- Owner: minikin
- License: mit
- Created: 2021-07-04T18:46:22.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-11-16T21:51:29.000Z (over 4 years ago)
- Last Synced: 2025-10-10T14:27:34.094Z (9 months ago)
- Topics: postgresql, rust, twitter
- Language: Rust
- Homepage:
- Size: 43.9 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
Twitter API Clone in Rust
[](https://github.com/minikin/twitter-rs/actions/workflows/rust.yml)
# Content
- [Requirements](#requirements)
- [Development](#development)
- [API](#api)
- [Support](#support)
- [License](#license)
### Requirements
- Rust on the stable channel
- PostgreSQL
### Development
1. Clone this repository & open in terminal.
2. Set `DATABASE_URL` env varibale.
```sh
export DATABASE_URL=postgres://user:password@localhost/twitter
```
2. Configure database
```sh
diesel setup
diesel migration run
```
4. Run program
```sh
cargo run
```
5. Call API:
```sh
curl -X POST -d '{"message": "Hello world!"}' -H "Content-type: application/json" http://localhost:9090/tweets
```
## API
- Create (`POST`) a tweet
```sh
curl -X POST -d '{"message": "Hello world!"}' -H "Content-type: application/json" http://localhost:9090/tweets
```
returns:
```json
{
"id": "584bca73-9d63-4801-bafc-ded7241a159f",
"created_at": "2020-07-04T13:35:48.059039Z",
"message": "Hello world",
"likes": []
}
```
- `DELETE` a tweet with `id`:
```sh
curl -X DELETE http://localhost:9090/tweets/90c76a57-8d6f-46cb-b68a-ef7dc67fdc6e
```
Return status code: 204 in any case.
- `GET` all tweets:
```sh
curl http://localhost:9090/tweets
```
returns list of tweets:
```json
{
"results": [{
"id": "90c76a57-8d6f-46cb-b68a-ef7dc67fdc6e",
"created_at": "2020-07-04T19:10:47.856376Z",
"message": "Hello world!",
"likes": []
}, {
"id": "584bca73-9d63-4801-bafc-ded7241a159f",
"created_at": "2020-07-04T19:04:01.448201Z",
"message": "Hey world!",
"likes": []
}]
}
```
- `GET` Tweet by `id`:
```sh
curl http://localhost:9090/tweets/90c76a57-8d6f-46cb-b68a-ef7dc67fdc6e
```
if tweet exists returns:
```json
{
"id": "90c76a57-8d6f-46cb-b68a-ef7dc67fdc6e",
"created_at": "2020-07-04T19:10:47.856376Z",
"message": "Hello world!",
"likes": [{
"id": "08a5f40f-4639-4882-8e0d-84ff84621461",
"created_at": "2020-07-04T19:22:29.095815Z"
}]
}
```
otherwise it returns status code `204`.
- `GET` list of likes for tweet with `id`:
```sh
curl http://localhost:9090/tweets/90c76a57-8d6f-46cb-b68a-ef7dc67fdc6e/likes
```
return list of like for tweet with `id`:
```json
{
"results": [{
"id": "08a5f40f-4639-4882-8e0d-84ff84621461",
"created_at": "2020-07-04T19:22:29.095815Z"
}]
}
```
- ADD (`POST`) one like to a tweet:
```sh
curl -X POST http://localhost:9090/tweets/90c76a57-8d6f-46cb-b68a-ef7dc67fdc6e/likes
```
returns:
```json
{
"id": "08a5f40f-4639-4882-8e0d-84ff84621461",
"created_at": "2020-07-04T19:22:29.095815Z"
}
```
- `DELETE` one like to a tweet
```sh
curl -X DELETE http://localhost:9090/tweets/90c76a57-8d6f-46cb-b68a-ef7dc67fdc6e/likes
```
## Support
Post issues and feature requests on the GitHub [issue tracker](https://github.com/minikin/twitter-rs/issues).
## License
The source code of a project is available under the MIT license.
See the [LICENSE](https://github.com/minikin/twitter-rs/LICENSE) file for more info.