AplikaceAplikace
Nastavení

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:manualy:api [2022/12/22 13:32] – [Getting a personal access token] michalkrenen:manualy:api [2022/12/29 19:11] (current) – [API] michalkren
Line 1: Line 1:
 ====== API ====== ====== API ======
  
-It is possible to access selected applications via an [[https://en.wikipedia.org/wiki/API|API]]. API access requires an authentication at all times and also for applications where this would not be necessary for their use via the standard user web interface. For the authentication, personal access tokens should be used.+Selected applications can be queried via an [[https://en.wikipedia.org/wiki/API|API]]. API access requires user authentication at all times, which holds also for applications where this would not be necessary for their use via the standard user web interface. For the authentication, personal access tokens should be used.
  
 ===== Getting your personal access token ===== ===== Getting your personal access token =====
Line 17: Line 17:
 A session cookie will be returned that should be used in every other request. It may be useful to save the session cookie and use it repeatedly within the next few hours. A session cookie will be returned that should be used in every other request. It may be useful to save the session cookie and use it repeatedly within the next few hours.
  
-Every application has an API tailored to its needs. API use manuals:+<WRAP tip important 60%> 
 +Individual API usage manuals:
   * [[https://github.com/czcorpus/kontext/wiki/HTTP-API|KonText]]   * [[https://github.com/czcorpus/kontext/wiki/HTTP-API|KonText]]
   * [[https://wiki.korpus.cz/doku.php/manualy:treq:api|Treq]]   * [[https://wiki.korpus.cz/doku.php/manualy:treq:api|Treq]]
 +</WRAP>
  
-===== Usage examples =====+The APIs can be queried at the following URLs: 
 +  * KonText: ''https://korpus.cz/kontext-api/v0.17'' 
 +  * Treq: ''https://treq.korpus.cz/api/v1''
  
-==== curl ====+<WRAP round important 60%> 
 +Every application also imposes its own **limits**. After exceeding them, there is a risk of blocking access to the API. 
 +  * **KonText**: max. 12 requests per minute and max. 5000 requests per day 
 +  * **Treq**: max. 30 requests per minute and max. 5000 requests per day 
 +</WRAP>
  
-Querying Treq+===== Usage examples ===== 
 + 
 +==== 1) curl and Treq API ====
  
 <code bash> <code bash>
Line 36: Line 46:
 </code> </code>
  
-==== Python Requests ==== +==== 2) Python and KonText API ====
- +
-Querying KonText+
  
 <code python> <code python>
Line 95: Line 103:
         "async": False         "async": False
     }     }
-    r = s.post('https://korpus.cz/kontext/query_submit', params={'format': 'json'}, json=request_body)+    r = s.post('https://korpus.cz/kontext-api/v0.17/query_submit', params={'format': 'json'}, json=request_body)
     response_json = r.json()     response_json = r.json()
     print(response_json)     print(response_json)
Line 101: Line 109:
     # Displaying a concordance     # Displaying a concordance
     conc_persistence_op_id = response_json['conc_persistence_op_id']     conc_persistence_op_id = response_json['conc_persistence_op_id']
-    r = s.get('https://korpus.cz/kontext/view', params={'format': 'json', 'q': '~'+conc_persistence_op_id})+    r = s.get('https://korpus.cz/kontext-api/v0.17/view', params={'format': 'json', 'q': '~'+conc_persistence_op_id})
     print(r.json())     print(r.json())