cezarykluczynski / stapi

STAPI, a Star Trek API
https://stapi.co
MIT License
123 stars 13 forks source link

How do I use this without Java? #5

Closed kachel closed 6 years ago

kachel commented 6 years ago

I would love to use your API for my first ever programming project!

I could not find a resource with the end point url or REST url. All of the tools listed are Java oriented. I am currently learning JavaScript.

For example, I found this link in the code, but that URL just the main page.

The path I am looking for is for the characters.

I am betting it will be something like characters/entity/Janeway.yaml but I cannot figure out the domain. What server should I make the request to?

tl:dr can you show me a curl command to get Janeway's info like gender or DOB.

Looking forward to you help! Thank you.

kachel commented 6 years ago

If you are curious, this is what I am working on atm: https://runkit.com/scrptktty/star-trek-gender.

cezarykluczynski commented 6 years ago

Hello.

STAPI cannot be currently queried using JavaScript in browser, because of unconfigured CORS policy. This can be bypassed using plugin like this one or anything that sets fake CORS headers. I'll try to fix that in the near future, so plugin won't be needed. If you are using node.js, CORS limitation does not apply.

All available services can be found here. REST services are on the bottom. Every service has the same layout: /character?uid=UIDHERE for querying for a single entity, and /character/search for searching.

To access characters, go to url like this one: http://stapi.co/api/v1/rest/character/search?pageNumber=0&pageSize=100

Then, just increment pageNumber until you reach a result that has page.lastPage property set to true, or a page that is empty. This is the last page now, and the next page is empty. The number of result can change in the future, so do not assume there will always be 59 pages of characters.

For the performers, do the same, but change character to performer in the URL, like this: http://stapi.co/api/v1/rest/performer/search?pageNumber=0&pageSize=100

To get Janeway specifically, you need to look her up using POST request. Just post to http://stapi.co/api/v1/rest/character/search?pageNumber=0&pageSize=100 with name set to Kathryn Janeway. Postman is a nice Chrome plugin to play around with REST APIs.

cezarykluczynski commented 6 years ago

Closing this one. Please let me know if you have any other issues.