Skip to content

Create api to manage user social network relationships with Nodejs and Neo4j

Notifications You must be signed in to change notification settings

ziranmyx/social-network-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Social Network API

A REST API for managing users and their social connections using Neo4j & Nodejs.

Project structure

src/
├── config/         # Database configuration
├── dao/            # Database interaction
├── services/       # Business logics
├── controllers/    # HTTP handlers
├── routes/         # API routes
├── errors/         # Error handling
└── docker/         # Local docker configuration

Quick Start with Docker

  1. Navigate to the project docker directory:
cd social-network-api/docker
  1. Start the services:
docker-compose up -d
  1. Seed the database with sample data:
docker exec social-network-api npm run seed
  1. The API will be available at http://localhost:3000/api

  2. Stop the services and remove all resources:

docker-compose down -v
  1. Check service logs:
docker logs  social-network-api  

Sample Data

The seed script creates 5 users with the following connections:

Connected: alice and bob with relationship (friend)
Connected: alice and charlie with relationship (colleague)
Connected: bob and diana with relationship (friend)
Connected: charlie and diana with relationship (family)
Connected: diana and eve with relationship (friend)
User IDs for testing:
   • alice: f73719a1-8cc2-45b3-8d79-151450a633bc
   • bob: f077b038-ba9a-47f2-ba7c-b3681e7f77e8
   • charlie: 1fc97d98-f66b-4b61-a540-a881f30d2f93
   • diana: c576e4da-7167-4dea-baf9-c295a49e4eb5
   • eve: a8be6c31-9527-4fec-9416-c7b6e315fb91

APIs

Healthcheck

GET /api/health

Users

Create User

POST /api/users
Content-Type: application/json

{
  "email": "ava@example.com",
  "username": "avama",
  "firstName": "Ava",
  "lastName": "Ma",
  "description": "Software engineer"
}

Get User by ID

GET /api/users/:id

Update User

PUT /api/users/:id
Content-Type: application/json

{
  "firstName": "Ava_update",
  "lastName": "Ma_update"
  "description": "Updated description"
}

Delete User

DELETE /api/users/:id

Connections

Create Connection

POST /api/connections
Content-Type: application/json

{
  "userId1": "user-1",
  "userId2": "user-2",
  "relationshipType": "friend"
}

Note: relationshipType defaults to "friend". Valid values: friend, colleague, family, other

Remove Connection

DELETE /api/connections
Content-Type: application/json

{
  "userId1": "user-1",
  "userId2": "user-2"
}

Search Users by Connection Degree

GET /api/connections/:userId/degree/:degree?limit=50

Returns list of users at with N degrees relationship from the given user (1-3)

About

Create api to manage user social network relationships with Nodejs and Neo4j

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published