silkapp / rest

Packages for defining APIs, running them, generating client code and documentation.

Home Page:http://silkapp.github.io/rest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Improving statics

bergmark opened this issue · comments

It's currently error-prone to use statics and I've made this mistake several times:

data Static = X | Y

resource :: Resource WithA WithB Ident Void Static
resource = mkResourceReader
  { R.name    = "foo"
  , R.schema  = noListing $ named
      [ ("id"          , singleRead ById  )
      , ( "x"          , static X         )
      ]
  , R.get     = Just get
  , R.statics = \case
      X -> x
      Y -> y
  }

This is missing a route to Y so this end point will be inaccessible and you won't get a warning.
Actions and selects do not have this problem since they don't require entries in both schema and actions.

Is there a reason statics are handled differently? Could we remove statics from schema and change the type of statics to [(String, Handler)]?

This is a broader problem, you can have the same with normal getters and listings. One issue I can think of with moving the statics outside of the schema is that it would be much easier to accidentally create overlapping schemas, where a static and a getter/list use the same key name.