News for hackers. Stuff that matters.
Re:Show HN: SWAPI – A Star Wars API by Adrock on Friday December 05, 2014 @09:39AM (#8704695)
Check out the author's blog post where he explains his motivation: http://phalt.co/if-you-have-data-they-will-consume-it/
Re:Show HN: SWAPI – A Star Wars API by idlewan on Friday December 05, 2014 @11:19AM (#8705235)
Is there a reason you're not using numbers in the json output?

    "vehicle_id": "1"
is better represented as:

    "vehicle_id": 1
Re:Show HN: SWAPI – A Star Wars API by erydo on Friday December 05, 2014 @12:51PM (#8705750)
I usually do the same thing. Both the 32-bit issue (that issue being with JSON libraries, not the spec) but also: IDs are opaque tokens. If down the road it makes sense to use UUIDs or have a sharding hash or something else, you don't want clients tied to expecting an integer datatype.
Re:Show HN: SWAPI – A Star Wars API by Igglyboo on Friday December 05, 2014 @04:10PM (#8706913)
I feel like a lot of people will see that an just cast it to an int however.
Re:Show HN: SWAPI – A Star Wars API by erydo on Friday December 05, 2014 @10:51PM (#8708285)
That could happen but in a lot of strictly typed languages it would be non-obvious and special effort to do so.

There's absolutely no justification to send ints when you have any reasonable chance of needing to change it to a string later. Besides, IDs in a public API fundamentally are not numbers. You don't add them, subtract them, multiply them, shift them, inspect any property of them besides equality, or anything. They're opaque tokens used to identify things with the server.

Re:Show HN: SWAPI – A Star Wars API by wise_young_man on Friday December 05, 2014 @11:21AM (#8705247)
What if the integer exceeds the maximum allowed on 32 bit machines and you try to decode the JSON?
Re:Show HN: SWAPI – A Star Wars API by djtriptych on Friday December 05, 2014 @11:25AM (#8705268)
That has nothing to do with JSON, which allows numbers of arbitrary size.
Re:Show HN: SWAPI – A Star Wars API by paulhallett on Friday December 05, 2014 @11:25AM (#8705269)
This is mostly just a typo in the examples I put, but I will consider using only strings for this type of stuff, to avoid issues.
Re:Show HN: SWAPI – A Star Wars API by idlewan on Friday December 05, 2014 @11:29AM (#8705292)
Given the dataset you have to serve, I don't think you'll be having any issues if most of the JSON parsers give you 32bit integers.
Re:Show HN: SWAPI – A Star Wars API by mcphage on Friday December 05, 2014 @09:31AM (#8704642)
Can I use the API to figure out that, for instance, the x-wing is /vehicles/1 and Mustafar is /planets/7? Otherwise, how would I know?
Re:Show HN: SWAPI – A Star Wars API by paulhallett on Friday December 05, 2014 @09:34AM (#8704662)
As well as ID, we'll do some fuzzy matching on the URLs as well, so

GET /api/vehicle/t-65-x-wing

and

GET /api/planets/mustafar

will also work

Re:Show HN: SWAPI – A Star Wars API by anonfunction on Friday December 05, 2014 @10:46AM (#8705050)
I think it would be nice to also provide an endpoint that lists all the resources as an array of objects where the key is the id and the value is the name. Maybe something like this:

  GET /resources/ships
  [
    { 1 : "Tantive IV" },
  ]
Re:Show HN: SWAPI – A Star Wars API by paulhallett on Friday December 05, 2014 @10:51AM (#8705072)
So RESTfully, I think this is normal. You should be able to call a resource and then be fed back all of those resources (usually paginated to say, 20 per request).

It will have this style of lookup.

Re:Show HN: SWAPI – A Star Wars API by svsaraf on Friday December 05, 2014 @11:30AM (#8705296)
Do you mind discussing how you did the fuzzy matching?

My initial guess would've been dynamic programming (levenstein distance), but if this is API-wide, did you make a suffix tree?

Re:Show HN: SWAPI – A Star Wars API by lttlrck on Friday December 05, 2014 @10:46AM (#8705047)
This doesn't work on pokeapi.co
Re:Show HN: SWAPI – A Star Wars API by paulhallett on Friday December 05, 2014 @10:50AM (#8705066)
PokeAPI is getting an update - http://phalt.co/if-you-have-data-they-will-consume-it/

and it will have better fuzzy matching.

Re:Show HN: SWAPI – A Star Wars API by anonfunction on Friday December 05, 2014 @09:18AM (#8704554)
I was so excited and then equally let down when I realized it wasn't online and this is just a coming soon page. Oh well, I signed up.
Re:Show HN: SWAPI – A Star Wars API by paulhallett on Friday December 05, 2014 @09:20AM (#8704567)
We're working on it, sorry!
Re:Show HN: SWAPI – A Star Wars API by anonfunction on Friday December 05, 2014 @09:24AM (#8704598)
No worries and thanks for building it. You may want to put the email capture above so it's more clear as I'm probably not the only one to copy pasta the url in the examples and be confused for a moment until scrolling to the bottom.
Re:Show HN: SWAPI – A Star Wars API by paulhallett on Friday December 05, 2014 @09:26AM (#8704612)
Good point. I set the URL config to catch all URLs and redirect back to the home page (anticipating people would try the API).

Once things die down I'll push up an update. Getting a heavy bit of traffic right now.

Re:Show HN: SWAPI – A Star Wars API by kcbanner on Friday December 05, 2014 @09:43AM (#8704728)
Any reason why this is an API and not a data dump?
Re:Show HN: SWAPI – A Star Wars API by paulhallett on Friday December 05, 2014 @09:46AM (#8704741)
I guess the main reason is that data dumps are sometimes hard to sift through, can become inconsistent (if there are multiple copies) and because from my experience, if you provide an API for something, someone will use it. On the flip side: I've found that often people have always asked "why isn't there an API for that?"

And of course, you can easily get a data dump from this by just cURLing all the resources and storing them :)

Re:Show HN: SWAPI – A Star Wars API by antihero on Friday December 05, 2014 @09:55AM (#8704775)
You don't really want to have to download potentially gigabytes of data to find a few sets of results!
Re:Show HN: SWAPI – A Star Wars API by TD-Linux on Friday December 05, 2014 @07:31PM (#8707808)
"potentially gigabytes of data" is now a microSD card smaller than my thumbnail, or alternately the cheapest instance on AWS.
Re:Show HN: SWAPI – A Star Wars API by paulhallett on Friday December 05, 2014 @11:27AM (#8705278)
Local caching will be the way to go.

All resources will have a "date_updated" or similar attribute which you can check against.

Re:Show HN: SWAPI – A Star Wars API by slapresta on Friday December 05, 2014 @04:28PM (#8707033)
Ahh, if only HTTP had defined a standard header for checking if the requested content has been modified, and sending a specific status code if that's the case...
Re:Show HN: SWAPI – A Star Wars API by reubenswartz on Friday December 05, 2014 @10:23AM (#8704935)
Not encouraging to see a basic error right on the front page: "From all six Star Wars films"

Couldn't resist... ;-)

Re:Show HN: SWAPI – A Star Wars API by paulhallett on Friday December 05, 2014 @10:25AM (#8704943)
Check the bottom of the page ;)

We'll have episode VII details as and when it gets released.

Re:Show HN: SWAPI – A Star Wars API by simonsayscode on Friday December 05, 2014 @10:36AM (#8705005)
I'm pretty sure it was a jibe at the fact that only 3 real Star Wars live-action films were made.
Re:Show HN: SWAPI – A Star Wars API by paulhallett on Friday December 05, 2014 @10:38AM (#8705010)
Ah, you didn't see the film_id & episode_id reference in the second example?
Re:Show HN: SWAPI – A Star Wars API by joshdotsmith on Friday December 05, 2014 @01:34PM (#8705999)
I feel like somewhere, somehow, a point is being missed.
Re:Show HN: SWAPI – A Star Wars API by reubenswartz on Friday December 05, 2014 @11:25PM (#8708339)
Paul, it's awesome. I'm just being snarky.

As @simonsayscode points out, some folks aren't big fans of Episodes I, II, and III. Here's hoping for a fun VII.

Re:Show HN: SWAPI – A Star Wars API by 1kevgriff on Friday December 05, 2014 @10:21AM (#8704925)
Signed up. This is going to be great for conference demos.
Re:Show HN: SWAPI – A Star Wars API by paulhallett on Friday December 05, 2014 @10:26AM (#8704947)
:D My other API for Pokémon is also great for demos and teaching APIs - http://pokeapi.co
Re:Show HN: SWAPI – A Star Wars API by ianakelly on Friday December 05, 2014 @11:36AM (#8705331)
I Virtualized this API just for kicks - https://vapi.ca.com/vapi/api/Vapidemouser/Star_Wars/planets/... and https://vapi.ca.com/vapi/api/Vapidemouser/Star_Wars/vehicles...

Would love more details and I can make a Virtual Copy of the whole thing.

Built it here https://vapi.ca.com

Re:Show HN: SWAPI – A Star Wars API by ianakelly on Friday December 05, 2014 @11:54AM (#8705442)
Re:Show HN: SWAPI – A Star Wars API by ukmadlz on Friday December 05, 2014 @09:18AM (#8704557)
This is amazing, all I need is a reason to mash http://pokeapi.co into this
Re:Show HN: SWAPI – A Star Wars API by paulhallett on Friday December 05, 2014 @09:19AM (#8704562)
Hi Mike, this is Paul, I am making this API too :D
Re:Show HN: SWAPI – A Star Wars API by ukmadlz on Friday December 05, 2014 @09:28AM (#8704619)
Yeah I know, I'be even used PokeAPI at a hack before. It's MusicHackDay soon, I may have to use it again as a reference for poke chiptunes
Re:Show HN: SWAPI – A Star Wars API by paulhallett on Friday December 05, 2014 @09:36AM (#8704682)
Please do :D
Re:Show HN: SWAPI – A Star Wars API by SvenAndersson on Friday December 05, 2014 @09:28AM (#8704616)
Hah! I'm in need of just this sort of API come January, what are the odds? Awesome, hope you launch soon!
Re:Show HN: SWAPI – A Star Wars API by paulhallett on Friday December 05, 2014 @09:33AM (#8704657)
ETA is end of January :)
Re:Show HN: SWAPI – A Star Wars API by anonfunction on Friday December 05, 2014 @10:50AM (#8705067)
Where are your getting the data?
Re:Show HN: SWAPI – A Star Wars API by paulhallett on Friday December 05, 2014 @10:52AM (#8705077)
Good ol' scraping from websites like wookiepedia.

And watching lots and lots of Star Wars.

I have the blurays, so I should be in for a fun experience whilst collecting the nitty gritty data.

Re:Show HN: SWAPI – A Star Wars API by slayed0 on Friday December 05, 2014 @10:58AM (#8705110)
Do yourself a favor and get the Despecialized Edition.

http://originaltrilogy.com/forum/topic.cfm/Harmys-STAR-WARS-...

Re:Show HN: SWAPI – A Star Wars API by afterburner on Friday December 05, 2014 @11:15AM (#8705219)
These are excellent. The little 'making of' documentary clip had me wondering what the fuss was about with the colour changes, but once I started watching I really appreciated it. Feels like popping the old VHS tapes in, but with modern resolution. Never knew how much it bothered me wondering if what I was watching was how I'd seen it originally (for the less obvious changes).
Re:Show HN: SWAPI – A Star Wars API by paulhallett on Friday December 05, 2014 @11:04AM (#8705148)
Oh that's a good point. Do I want my data to be consistent with the 1997 releases or the originals!?
Re:Show HN: SWAPI – A Star Wars API by delinka on Friday December 05, 2014 @11:08AM (#8705182)
If it's "All The Star Wars data [We]'ve Ever Wanted," then I want both. With tags telling me which data is 'original' and which changed in the '97 releases.

EDIT: And a donate button so I can reward you.

Re:Show HN: SWAPI – A Star Wars API by happyscrappy on Friday December 05, 2014 @11:23AM (#8705256)
Re:Show HN: SWAPI – A Star Wars API by acomjean on Friday December 05, 2014 @09:03AM (#8704487)
Totally ridiculous, but awesome at the same time.

Make that API great!

Whats the backend?

Re:Show HN: SWAPI – A Star Wars API by paulhallett on Friday December 05, 2014 @09:07AM (#8704505)
Hey! Thanks. I made the Pokémon API as well - http://pokeapi.co

The backend on that is Django. I might stick with what I know, or build SWAPI in Go. At the moment, we're still very early stage, so we can choose soon.

Re:Show HN: SWAPI – A Star Wars API by emillon on Friday December 05, 2014 @10:20AM (#8704921)
Under which license is this data available?
Re:Show HN: SWAPI – A Star Wars API by paulhallett on Friday December 05, 2014 @10:25AM (#8704941)
The data is being scraped from sources online and by watching the films about a thousand times.

As the data is already available freely elsewhere, I won't be charging or keeping the data, I'll provide it just like I do on http://pokeapi.co

Re:Show HN: SWAPI – A Star Wars API by rakoo on Friday December 05, 2014 @01:09PM (#8705868)
Thank you for what you're doing, that's awesome! I'd like to enlighten why choosing a license is important.

Many people can be picky about the license, because even though you may be full of good intentions, the data you provide is non-free as-is in that it can't be reused elsewhere. Having a license is the clean, boring way to tell everyone "do whatever you want with this data".

That's even a problem for Github, or more precisely Github users, because many people push some code without any explicit license, making this code hardly usable by default: it may be available but you don't know if you have the right to reuse it, even if the developer said "yeah, use this as you want". That's not enough. Just because the developer didn't take a few minutes to select and put a LICENSE file.

It is also important to think about it in the other direction: If you're going to take content from Wookieepedia, their license is CC-BY-SA (http://starwars.wikia.com/wiki/Wookieepedia:Copyrights), which means that you MUST say it comes (at least partially) from them (not that you wouldn't anyway) and that you MUST redistribute your content with a "similar" license. Even though you may think that everything is fine, there are some actions to do on this side.

Now, I'd understand that if only "amateurs" come and play with the data, we're all among good behaving adults and all is fine. But you may not be able to predict what will happen with how data is used, so unfortunately this step is important.

Personally I don't like restricting people, so I try to use CC0 as much as possible. Be aware that Creative Commons licenses may not be best suited for data (they were designed for work of art primarily), as can be seen by OSM's decision on the matter (http://www.osmfoundation.org/wiki/License/We_Are_Changing_Th...) so you may want to avoid them.

Note: I'm not even talking about money, which is an orthogonal problem.

Re:Show HN: SWAPI – A Star Wars API by gegtik on Friday December 05, 2014 @09:18AM (#8704560)
Luke Sykwalker
Re:Show HN: SWAPI – A Star Wars API by paulhallett on Friday December 05, 2014 @09:20AM (#8704574)
Good spot!