An API to simulate a social network where members can friend each other. Uses Express and a file system for data storage.
Install Node dependencies:
npm install
Start server on localhost:3000
:
npm run start
Path | Method | Description |
---|---|---|
/members | GET | Get all members |
/member/:id | GET | Get member |
DELETE | Delete member and all friendships associated with it | |
/member/:id/friends | GET | Get member's friends |
/member/:id1/friend/:id2 | GET | Get member's friend (or empty set if the two members are not friends) |
POST | Add member as friend | |
DELETE | Remove member as friend | |
/member/:id/feed | GET | Get member feed consisting of friends' statuses |
/register | POST | Create new member |
The data
directory contains two files: members.json
and friendships.json
.
The members.json
file contains mock data that was generated using Mockaroo. It contains 50 rows and these fields (using Mockaroo's attributes):
Field Name | Type |
---|---|
id | Row Number (Primary Key) |
username | Username |
first_name | First Name |
last_name | Last Name |
Email Address | |
gender | Gender |
birthdate | Datetime |
avatar | Avatar |
status | Sentences |
The friendships.json
file was generated using the src/friends-script.js
script. It consists of randomly assigned friendships between the members in members.json
. A friendship is denoted by the key-value pair member1_id: member2_id
. The fields look like this:
Field Name | Type |
---|---|
member1_id | Row Number (Foreign Key) |
member2_id | Row Number (Foreign Key) |
The following command can be used to generate new friendships:
node src/friends-script.js [max_friends]
The optional max_friends
argument specifies the maximum number of friends a single member can have. The default value is 25.