REST, OData, GraphQL, SignalR

The Problem with RESTful APIs

Practical RESTful APIs

  • Design APIs around business entities
    • Customers, Orders, Products, etc.
  • Uses many concepts of HTTP
    • URL for addressing and joining, query parameters, headers for authentication, methods for operations, etc.
  • Schema and documentation using Open API Specification
https://api.acme.com/customers
https://api.acme.com/customers/ALFKI
https://api.acme.com/customers/ALFKI/orders
https://api.acme.com/customers/ALFKI/orders/4711
https://api.acme.com/orders?skip=100&take=10
...

Problem: Overfetching, Underfetching

  • Overfetching
    • https://api.acme.com/customers/ALFKI returns an entire customer
    • What if the client only needs specific fields?
  • Underfetching
    • https://api.acme.com/orders returns order headers
    • What if the client needs order details for all orders (N+1 problem)
  • Logic on the client
    • https://api.acme.com/customers returns customers ordered by ID
    • What if the client needs data ordered by customer name?

Solutions

  • Add more endpoints
    • https://api.acme.com/customers/orderedByName
    • 👍 simple to implement for only a few options
    • 👎 confusing for larger APIs, a lot of work, inflexible
  • Use query parameters
    • https://api.acme.com/customers?orderBy=name
    • 👍 flexible, arbitrarily powerful
    • 👎 not standardized

OData

What is OData?

Pros/Cons

  • Solves over/underfetching problem
    • Gives client a lot of flexibility
  • Standardized
    • OASIS standard
    • Widely used in Microsoft products (clients, services)
    • Covered in Microsoft's own API Guidelines 🔗
    • No so widely used outside the MS ecosystem
  • Good integration with .NET
    • Largely delivered by Microsoft
  • Well-suited for use with (relational) databases
    • OData queries can be relatively easy translated
      into DB queries (e.g. SQL)
  • Not the newest and freshest protocol

.NET and OData

GraphQL

What is GraphQL?

What is GraphQL?

Pros/Cons

  • Solves/moves over/underfetching problem
    • Gives client a lot of flexibility
  • Popular
    • Widely used in modern distributed systems 🔗
    • Support in many popular tools (e.g. Postman 🔗)
  • No .NET support provided by Microsoft, but from 3rd parties
  • Not so well-suited for use with (relational) databases

.NET and GraphQL

  • Two popular GraphQL server implementations
  • Decent integration with Entity Framework Core
    • 👍 Integration with EFCore 🔗, support for IQueryable 🔗
    • 👎 GraphQL not designed primarily with DBs in mind
  • Implementation of custom GraphQL providers is possible
    • 👍 Flexibility
    • 👎 A lot of work to do it right

SignalR

What is SignalR?

SignalR without SignalR 😕

.NET and SignalR

Other Options

Invent Your Own QL

  • Invent your own query language
    • Based on existing grammar (e.g. JSON, YAML)
    • Custom grammar (DSL)
  • Frequently done in COTS SaaS applications, examples:
  • Pros/Cons
    • 👍 Flexibility, can be tailored to specific needs
    • 👎 Complexity, a lot of (interesting) work (done it before)

gRPC

The Ideal Option

Data Access Layer

Business Logic Layer

OData

GraphQL

gRPC

...

Q&A

REST, OData, GraphQL, SignalR, gRPC

By Rainer Stropek

REST, OData, GraphQL, SignalR, gRPC

  • 595