Skip to content

REST and GraphQL APIs to compare the benefits of GraphQL. Created for use in a Group Tutorial demonstration at the University of Exeter.

License

Notifications You must be signed in to change notification settings

Thomas-Smyth/REST-vs-GraphQL-Example

Repository files navigation

REST vs GraphQL Example API

GitHub release GitHub issues GitHub pull requests GitHub contributors GitHub license

REST and GraphQL API Interfaces for a Basic Social Media Application


Installation

To install via npm:

cd REST
npm install
cd ../GraphQL
npm install

To install via yarn:

cd REST
yarn install
cd ../GraphQL
yarn install

Starting the API Servers

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

REST Endpoints

  • /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.

GraphQL Schema

  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
  }

Postman

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.

Motivation

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.

Contributing

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!

About

REST and GraphQL APIs to compare the benefits of GraphQL. Created for use in a Group Tutorial demonstration at the University of Exeter.

Resources

License

Stars

Watchers

Forks

Packages

No packages published