TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: Given an API, Generate client libraries in Node, Python, PHP, Ruby

268 pointsby sunkarapkover 11 years ago
PS: Assuming a REST architecture.

22 comments

gamacheover 11 years ago
Wouldn&#x27;t it be wiser to choose a hypermedia format for the API, and then use a generic hypermedia client on whichever platform you like? Then you write just as many client libraries (zero), but the problem of pushing updates to your clients is solved as well.<p>Full disclosure: I wrote such a library for Ruby, called HyperResource. <a href="https://github.com/gamache/hyperresource" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;gamache&#x2F;hyperresource</a>
评论 #7006692 未加载
评论 #7006255 未加载
评论 #7006340 未加载
sunkarapkover 11 years ago
Author here. I covered almost everything in the documentation. And there is also a small example which is hosted at <a href="https://github.com/alpaca-api" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;alpaca-api</a>.<p>Please ask if you have any questions. Thanks
评论 #7005471 未加载
评论 #7006653 未加载
jxfover 11 years ago
Just tried this out and Alpaca is an awesome tool. However, I&#x27;d never want to release this in production without tests. Alpaca doesn&#x27;t generate tests, so you&#x27;re back to maintaining the tests for your N different platforms&#x2F;languages. But you&#x27;d have the same problem with its competitors, too; Thrift [0], for instance, doesn&#x27;t generate tests either.<p>Overall, I&#x27;m not sure that the time savings is as big as it first appears, but I think it&#x27;s great for quick projects.<p>[0] <a href="http://thrift.apache.org/" rel="nofollow">http:&#x2F;&#x2F;thrift.apache.org&#x2F;</a>
评论 #7005740 未加载
评论 #7010605 未加载
评论 #7006453 未加载
kimmelover 11 years ago
I like the SPORE (Specification to a POrtable Rest Environment) approach better. You create a description file in JSON and each native language client can use that file to access the HTTP API. <a href="https://github.com/SPORE/specifications" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;SPORE&#x2F;specifications</a><p>SPORE already has clients for Clojure, Javascript, Lua, NodeJS, Perl, Python, and Ruby. I have used SPORE in a few projects and I was not disappointed. Another approach to solving the cross language library problem.
评论 #7010234 未加载
memsetover 11 years ago
This is cool. I would suggest that it would be very useful to have this kind of thing for JSON Schema [1], which is what I use with Python code to validate incoming JSON. (I was originally hesitant to using that, but since getting into it, I have yet to run into a use case which it cannot handle.)<p>There is also an RFC for &quot;JSON Hyper Schema&quot; which is intended to describe REST APIs. It doesn&#x27;t have much library support in much of everything, but I am surprised that it hasn&#x27;t taken off!<p>I like that this library is fairly opinionated (options for how to authenticate, supported formats, etc.) Though I worry that that creates a bit of inflexibility - for what exactly does &quot;oauth&quot; actually mean, there are always vagaries.<p>Neato!<p>[1] <a href="http://json-schema.org/" rel="nofollow">http:&#x2F;&#x2F;json-schema.org&#x2F;</a>
mikekekekeover 11 years ago
Am I right in thinking about this like a WSDL, but based on JSON?
评论 #7005639 未加载
评论 #7007840 未加载
squar1smover 11 years ago
I think this is fantastic. @sunkarapk, great job. That it&#x27;s written in Go makes using it so much easier. Wonderful.
codereflectionover 11 years ago
I have to admit, this is very reminiscent of &quot;Add Service Reference&quot; in Visual Studio, a capability to which I have grown to despise over the years. The code was almost always incomprehensible. I cannot tell you how much I loath seeing the comment at the top of a file &quot;This was generated by a tool&quot;.<p>Having said that, this tool does look interesting. I hope that a goal is to always make sure that the generated code is as readable, and maintainable, as possible. Also, as mentioned by others, adding generated tests to the generated client libraries is extremely important.
评论 #7007876 未加载
johnnyioover 11 years ago
Describing an API is not hard, but the API authentication method is. How do you think you will do it?<p>Edit : If you don&#x27;t make oauth consumption simpler, you don&#x27;t really solve the problem
评论 #7005494 未加载
jodoglevyover 11 years ago
Very cool, but why come up with a new API schema rather than use an open standard like OData (<a href="http://www.odata.org/" rel="nofollow">http:&#x2F;&#x2F;www.odata.org&#x2F;</a>)? Then Alpaca would be compatible with a bunch of APIs that already exist today. In fact, something like this (generating client libraries from APIs) may exist for OData already, but if it does, I&#x27;ve only seen it for .NET and OData (Visual Studio &#x27;Add Service Reference&#x27;).<p>This is actually pretty similar to a side project I&#x27;ve been working on called Gargl (Generic API Recorder and Generator Lite) (<a href="https://github.com/jodoglevy/gargl" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;jodoglevy&#x2F;gargl</a>). Haven&#x27;t gotten around to doing a Show HN post yet, but would love any feedback or to combine efforts. Basically it lets you generate an API for websites that don&#x27;t have APIs publically available, by looking at how a web page &#x2F; form submission of that web site interacts with the web server. You record web requests you make while normally browsing a website via a chrome extension, parameterize them as needed, and then output your &quot;API&quot; to a template file. Then this template file can be converted to a client library in a programming language of your choosing.
acbartover 11 years ago
So, this is markedly similar to the project I&#x27;ve been working on in grad school, only without static typing. <a href="http://research.cs.vt.edu/vtspaces/realtimeweb/" rel="nofollow">http:&#x2F;&#x2F;research.cs.vt.edu&#x2F;vtspaces&#x2F;realtimeweb&#x2F;</a> Also, mine is explicitly geared towards education purposes. I&#x27;m about one third of the way thru version two, but I wonder if we can cross pollinate our code bases to get something even better.
pjmlpover 11 years ago
Can we please stop calling Web Services APIs?
评论 #7006102 未加载
评论 #7005575 未加载
endeavourover 11 years ago
Does this use the Json Schema spec or have you reinvented the wheel?
评论 #7006098 未加载
mjsover 11 years ago
Regarding bug reports:<p>&gt; Guaranteed reply within a day.<p>That seems difficult to achieve--wonder how they&#x27;re doing that? (Also, why??)
评论 #7006242 未加载
评论 #7006264 未加载
abengoamover 11 years ago
That looks fantastic, and seems to be in alignment with some things I have been doing lately (generating the server side controller of the API in Clojure + a set of documentation, from a set of definitions of API methods). Good job!
mmccaffover 11 years ago
Well done!<p>Know what I think would be really neat? If it could be pointed at an instance of Swagger-UI, or use the same discoverUrl that Swagger-UI would use, and spit out the libraries from that.<p>If you&#x27;re not familiar.. <a href="https://github.com/wordnik/swagger-ui" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;wordnik&#x2F;swagger-ui</a>
bashtianover 11 years ago
I did something similar for Go and Java. It&#x27;s simpler if you don&#x27;t need the whole API, but of course not as powerful. <a href="https://github.com/bashtian/jsonutils" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;bashtian&#x2F;jsonutils</a>
reklaklislawover 11 years ago
fwiw, I experimented along this line, dynamically generating python wrappers from yaml: <a href="https://github.com/reklaklislaw/rest_easy" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;reklaklislaw&#x2F;rest_easy</a><p>It lacks documentation, a bunch of features, and parts smell pretty bad, but since the topic came up I thought maybe someone would find it interesting, if only vaguely.
egonschieleover 11 years ago
Useful, well-documented, TODOs right in the readme, and fast response for pull requests. I wish every open source project was like this.
elwellover 11 years ago
Great idea! Including Obj-C would be very helpful.
flippyheadover 11 years ago
I&#x27;ve been enjoying <a href="http://apiblueprint.org" rel="nofollow">http:&#x2F;&#x2F;apiblueprint.org</a>
评论 #7007020 未加载
notastartupover 11 years ago
oh man you just killed a major feature of mashape.com
评论 #7009538 未加载