To install via npm
:
cd REST
npm install
cd ../GraphQL
npm install
To install via yarn
:
cd REST
yarn install
cd ../GraphQL
yarn install
Run the following in the REST / GraphQL folders depending on which you wish to start.
You can run both servers at the same time. Port 3000
for REST, port 3001
for GraphQL.
Start with npm
:
npm run build
npm run start
Start with yarn
:
yarn run build
yarn run start
/users
- Get all users./users/:id
- Get user by ID./posts
- Get all posts./posts/:id
- Get post by ID./reactions
- Get all reactions./reactions/:id
- Get reactions by ID.
type User {
id: Int
username: String
email: String
posts: [Post]
reactions: [Reaction]
}
type Post {
id: Int
user: User
text: String
reactions: [Reaction]
}
type Reaction {
id: Int
user: User
post: Post
type: String
}
type Query {
user(id: Int): User
users: [User]
post(id: Int): Post
posts: [Post]
reaction(id: Int): Reaction
reactions: [Reaction]
}
schema {
query: Query
}
A Postman collection has been exported and added to this repository. It contains a examples to cover all REST endpoints and a single GraphQL example.
To use the collection:
- Open Postman
- File > Import
- Select the Postman Collection JSON file from the repositories root.
The creation of this repository was motivated by the need to demonstrate the benefits of GraphQL APIs to fellow students, at the University of Exeter, some of which may have never had any experience using APIs.
Through demos of both REST and GraphQL APIs to implement the same basic functionality of a mock social media application, this repository has enabled me to demonstrate clearly the direct benefits of GraphQL over REST APIs to these students.
I am making this repository public to allow those in the same position to use this resource.
I am accepting contributions to this project, so for those who wish to help improve and build on this resource simply create a pull request and I will review it as soon as possible!