Server Side Swift with Vapor: RESTful Controllers | Ray Wenderlich

Learn how to create a RESTful interface for your model objects in Vapor, a popular server side swift framework.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/4948-server-side-swift-with-vapor-restful-controllers

Is there a wst to expose to the outside world which functionality is available on the Api? Like an api doc?

AFAIK there is nothing built-in to do this, but you could roll your own.

API Documentation
Have you ever used http://swagger.io/? Or do you know any other alternatives?
Since we’re writing APIs thought it might make a good tutorial on making documentation for it.

swagger supports generation of code for various server and client platforms. It would be very cool if it would support server-side swift, like Vapor.

I need some help.

I cant show any data from my table, this is the error:
This is my code:

https://gist.github.com/willianpinho/ 5e4b5bca8c6ee2189c177df1bef4cf8d

My request show null, and received that error:

Could not initialize User, skipping: unableToConvert(nil, “String”)

Hi,

How would I retrieve the acronym using the ‘short’ field (i.e. not by its id) ?
I assume I have to create a route e.g. acronyms/short/WTF, but how to get the acronym from the db ?

Thanks,
Andy

Hi! I encountered this Could not initialize Card, skipping: unableToConvert(nil, “String”) issue and after many experiments, I think I found a solution (or at least a workaround).

For some context, I’m building a Card game and using PostgreSQL. The Card model had the following property:

var cardType: String

In the init(node: Node, in context: Context) method, there I see this error if the extract keys are not lowercase.
cardType = try node.extract(“cardtype”)

A lot of research to get to this point, but hopefully is solves your problem. While I prefer camel case, the database drivers providers don’t quite play nice here so I have opted for card_type and similar property naming even if it isn’t very swifty.

Hope that helps!

1 Like

Solved my problem! I was trying to use camel case in my node.extract() keys as well. When I look at the table in Postgres all the field names are lower case. Thank you so much for posting this!

Hy,
Will you update to Vapor 2?
Thanks in advance.