Code Monkey home page Code Monkey logo

battleoftheapi's Introduction

BattleOfTheApi

Simple C# implementations of various HTTP based API using a common data set hosted in PostgreSQL.

To Run

Pick one:

  • docker-compose up from within /src/
    • Use docker ps to see which host ports are being bound to each API
  • Open the Visual Studio Solution file (.sln), run the docker-compose project
  • Target and run a single API .csproj with either the dotnet CLI, VS Code, or Visual Studio
    • NOTE: If you run an individual project, you'll need to setup and configure the connection for your own Postgres DB instance as docker-compose is otherwise doing that

Instructions on how to query the API can be found in README in their respective project directories.

Available API

  • Open API
  • REST
    • JSON API
  • gRPC

Planned API

Implementation Notes

Open API

Uses auto generated (via Swashbuckle) Open API docs along with the Swagger UI to make exploring the API easy. Clients generate URLs from endpoints specified in the Open API document.

REST

Per the creator of REST, Roy Fielding, for an API to truly be rest, it must use Hypermedia As The Engine of Application State (HATEOAS). This in theory should make the API self documenting such that a client could organically discover what functions are avialable as they use the API.

These API implemented here seem to at least attempt to do so by including links in their representations.

JSON API

It does add links for its resources, but only for data relationships. There are no rels that tell the user what actions are available. Does this actually qualify as HATEOAS?

The JSON API project intentionally does not have a Swagger doc. There is a Postman collection in the project directory that can be

It does generate some very useful features with very little boiler plate code. The boiler plating is reduced even further if you use Entity Framework. If you follow their conventions, you get the following features for "free":

  • Linking of related objects
  • Pagination
  • Sorting
  • Filtering
  • Fieldset selection (kinda like GraphQL)
  • Read/Write access control via attributes

GraphQL

  • Specification

  • Library used

  • Offers streaming between client-server via web sockets

  • Allows client to specify fields to avoid under/over fetching

gRPC

The gRPC API is a Google creation that uses Google's Protobuf binary serialization. There are official frameworks for most of the popular languages including C#.

The implemented Services follow closely to the Open API controllers. However, since gRPC uses binary serialization, it cannot be queried with traditional HTTP plain text clients. There are instructions in the project specific README on how to use grpcc to query the API.

Since gRPC uses binary, it offers faster serialization and transport. The trade off is that it uses "proto" files as the contract between apps and is more strict about message structure than JSON as well as not having human readable messages. This would make it well suited for back end inter-service communication.

battleoftheapi's People

Contributors

aerotog avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.