Aplikasi API sederhana menggunakan Golang
- PostgreSQL
- Database Name: mygram
- Database User: postgres
- Database Password: root
- Database Port: 5432
[!] You can change the database configuration in the file models/setup.go
go mod tidy
go run main.go
This will runing on default localhost port 8080
You can import this postman collection to test the API
[!] Collection file in folder test
[!] Remember after login, you need to copy the token and paste it in the header Authorization with Bearer Token manually
-
Register User
-
Login User
-
Update User
-
Delete User
-
Create Photo Post
-
Update Photo Post
-
Delete Photo Post
-
Create Comment
-
Update Comment
-
Delete Comment
-
Create User Social Media
-
Update User Social Media
-
Delete User Social Media
Register User
*Note : username and email is unique
curl --location --request POST 'http://localhost:8080/users/register' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'Username=example' \
--data-urlencode 'Email=yourmail' \
--data-urlencode 'Password=yourpassword' \
--data-urlencode 'Age=yourage'
Login User
curl --location --request POST 'http://localhost:8080/users/login' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'Email=yourMail' \
--data-urlencode 'Password=yourPassword'
This will return token, save it for next request
Update User
curl --location --request PUT 'http://localhost:8080/users/update' \
--header 'Authorization: Bearer {YOURTOKEN}' \
--header 'Content-Type: application/json' \
--data-raw '{
"email": "updateyourmail@test.com",
"username": "updateyourname"
}'
Delete User
curl --location --request DELETE 'http://localhost:8080/users/' \
--header 'Authorization: Bearer {YOURTOKEN}'
Token is required
Get All Your Photo Post
curl --location --request GET 'http://localhost:8080/posts/' \
--header 'Authorization: Bearer {YOURTOKEN}'
Create Photo Post
curl --location --request POST 'http://localhost:8080/photos' \
--header 'Authorization: Bearer {YOURTOKEN}' \
--header 'Content-Type: application/json' \
--data-raw '{
"title": "your title",
"caption": "your caption",
"photo_url": "your photo url"
}'
Update Photo Post
curl --location --request PUT 'http://localhost:8080/photos/{PHOTOID}' \
--header 'Authorization: Bearer {YOURTOKEN}' \
--header 'Content-Type: application/json' \
--data-raw '{
"title": "update your title",
"caption": "update your caption",
"photo_url": "update your photo url"
}'
Delete Photo Post
curl --location --request DELETE 'http://localhost:8080/photos/{PHOTOID}' \
--header 'Authorization: Bearer {YOURTOKEN}'
Get All Your Comment
curl --location --request GET 'http://localhost:8080/comments/' \
--header 'Authorization: Bearer {YOURTOKEN}'
Post Comment
curl --location --request POST 'http://localhost:8080/comments' \
--header 'Authorization: Bearer {YOURTOKEN}' \
--header 'Content-Type: application/json' \
--data-raw '{
"message": "your message",
"photo_id": {PHOTOID}
}'
Update Comment
curl --location --request PUT 'http://localhost:8080/comments/{COMMENTID}' \
--header 'Authorization: Bearer {YOURTOKEN}' \
--header 'Content-Type: application/json' \
--data-raw '{
"message": "update your message"
}'
Delete Comment
curl --location --request DELETE 'http://localhost:8080/comments/{COMMENTID}' \
--header 'Authorization: Bearer {YOURTOKEN}'
Get All Your User Social Media
curl --location --request GET 'http://localhost:8080/socialmedias' \
--header 'Authorization: Bearer {YOURTOKEN}'
Create User Social Media
curl --location --request POST 'http://localhost:8080/socialmedias' \
--header 'Authorization: Bearer {YOURTOKEN}' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "your social media name",
"social_media_url": "your social media url"
}'
Update User Social Media
curl --location --request PUT 'http://localhost:8080/socialmedias/{SOCIALMEDIAID}' \
--header 'Authorization: Bearer {YOURTOKEN}' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "update your social media name",
"social_media_url": "update your social media url"
}'
Delete User Social Media
curl --location --request DELETE 'http://localhost:8080/socialmedias/{SOCIALMEDIAID}' \
--header 'Authorization: Bearer {YOURTOKEN}'