📜 ⬆️ ⬇️

Great words: API

Great words In February last year, we presented our project “ Great Words ”. In this topic, I want to present our API, created so that third-party developers can create their products based on our project. Now use quotes in their workings easily and simply.

Our API "communicates" in XML . Below is the request format and response format. All you have to do is send a request to http://api.greatwords.ru/ and parse the answer.

Previously, to start using the API, you need to write us a letter (see the address on the page http://api.greatwords.ru/ ) in which you need to specify in which software product (application, widget, website) quotations will be used. After that you will receive a unique key (API key), which you will need to transfer in the request.

Requests are accepted by the GET and POST methods. The request can use the following parameters:
  1. apikey = <API key> - your unique key (required parameter);
  2. by = (author | keyword | user | favorites | random | new) - by what parameter (by author, by label, by added user, from selected user, by chance, new by date) you want to get a quote or quotes (required parameter );
  3. condition = <condition> - condition; the condition can be an author identifier, a label or a user, as well as the name of the author, a label word, user login or search query (optional parameter);
  4. count = <number> - the number of citations you need (optional);
  5. random = 1 is a parameter indicating that you need randomly selected quotes that satisfy the condition (optional parameter).

For example, to get all quotes for the tag “ love ”, the query should look like this: by = keyword & condition = 7 (where 7 is the id of this tag). In addition, you can use the following type of query: by = keyword & condition = love , but in this case, pay attention to the fact that the text must be in UTF-8 encoding.
')
Another example: you need to get 10 random quotes. In this case, the query should look like this: by = random & count = 10 . And to get 10 new quotes, use the query by = new & count = 10 .

And, finally, an example if you want to receive a random quote from your favorites each time. Then you need to use the following query: by = favorites & condition = <id> & count = 1 & random = 1 (where <id> is your user ID) or even by = favorites & condition = <login> & count = 1 & random = 1 (where <login> is your login ).

The answer is formed in the following format:
<greatwords>
<quote>
<link> http://greatwords.ru/quote/20/ </ link>
<content> Being born stupid is not a shame, it is a shame only to die a fool. </ content>
<author>
<name> Erich Maria Remarque </ name>
<link> http://greatwords.ru/author/2/ </ link>
</ author>
<source> "Three Comrades" </ source>
<year> 1938 </ year>
</ quote>
<quote>
...
</ quote>
</ greatwords>

When using the API, the hyperlink to greatwords.ru and / or to the pages of authors / citations is required.

Source: https://habr.com/ru/post/72066/


All Articles