API:Main page/hi


 * यह एपीआई द्वारा कार्य का अवलोकन है। दायें ओर में दिये मेनू को इसके उपविषय और एपीआई से जुड़े जानकारी हेतु देखें।

मीडियाविकि एपीआई एक वेब सेवा है, जो आपको विकि के विशेषता, डाटा, आदि को एचटीटीपी या यूआरएल द्वारा जो मुखतः  होता है। कोई भी विशेष कार्य हेतु  दे सकता है। जो मुख्यतः   होता है, यह जानकारी प्राप्त करने के लिए उपयोग किया जाता है। यह पहले  एक  मीडियाविकि एपीआई के रूप में जाना जाता था। लेकिन अब वेब एपीआई भी उपलब्ध हो गया है, जो रेस्टबेस और विकिडाटा कुएरी सेवा नाम से जाना जाता है।

प्रस्तावना
यदि आप "आंतरिक एपीआई" या "पीएचपी एपीआई" का उपयोग करना चाहते हैं, तो extension interface देखें, जो आपको पीएचपी के कई कार्यों और मीडियाविकि के स्थापन के बारे में बताता है।

मीडियाविकि का एपीआई आप मीडियाविकि के स्थापन की देख रेख में भी कर सकते हैं, या आप कोई बॉट का निर्माण कर स्वतः इसकी देख रेख कर सकते हैं। यह सीधे ही उच्च-स्तर में डाटा पर नियंत्रण स्थापित करने देता है। ग्राहक कार्यक्रम द्वारा वे विकि पर प्रवेश कर डाटा ले सकते हैं और बदलाव भेज सकते हैं। यह स्वतः ही एचटीटीपी द्वारा होता है। Supported clients include bots, thin web-based JavaScript clients such as Navigation popups and LiveRC, end-user applications such as Vandal Fighter, and other web sites ([//tools.wmflabs.org Tool Labs]' utilities).

On new MediaWiki installations, the web service is enabled by default, but an administrator can disable it.

MediaWiki has two other outward-facing interfaces:


 * Special:Export पृष्ठ आपको एक साथ कई विकि सामग्री को एक्सएमएल प्रारूप में डालने कि सुविधा प्रदान करता है। Read the Export help article on meta.wikimedia.org for more information.
 * The standard web-based interface (which you are likely using right now to view this page). वेब आधारित उपयोग हेतु को पढ़ें।

एक सरल उदाहरण
This URL tells English Wikipedia's web service API to send you the content of the main page:

https://en.wikipedia.org/w/api.php?action=query&titles=Main%20Page&prop=revisions&rvprop=content&format=json

Use any programming language to make an HTTP GET request for that URL (or just visit that link in your browser), and you'll get a JSON document which includes the current wiki markup for the page titled "Main Page". Changing the format to  will return a "pretty-printed" HTML result good for debugging.

Let's pick that URL apart to show how it works.

The endpoint
This is the endpoint. यह मीडियाविकि वेब के एपीआई का मुखपृष्ठ के समान ही है। यह यूआरएल अंग्रेज़ी विकिपीडिया के एपीआई का आधार यूआरएल है। यह केवल  ही है।

यदि आप कोई कार्यक्रम अंग्रेज़ी विकिपीडिया में उपयोग करने के लिए लिख रहे हैं, तो उसका हर पता इस आधार यूआरएल पर आधारित होना चाहिए। If you're using a different MediaWiki installation, you'll need to find its endpoint and use that instead. All Wikimedia wikis have endpoints that follow this pattern:

Since, we have RSD discovery for the endpoint: look for the  in the HTML source of any page and extract the   URL; the actual link contains additional info. For instance, on this wiki it's:

Otherwise, there's no safe way to locate the endpoint on any wiki. If you're lucky, either the full path to index.php will not be hidden under strange rewrite rules so that you'll only have to take the "edit" (or history) link and replace index.php (etc.) with api.php, or you'll be able to use the default script path (like ).

Now let's move on to the parameters in the query string of the URL.

प्रारूप
यह एपीआई को बताता है कि आप डाटा को जेसन प्रारूप में प्राप्त करना चाहते हैं। आप शायद यह भी उपयोग करना चाहे  जिससे आप इसका एचटीएमएल संस्करण प्राप्त कर सकते हो। यह परीक्षण के दौरान त्रुटि जाँच करने में सहायक होता है। The API supports other output formats such as XML and native PHP, but there are plans to remove less popular formats (T95715), so you might not want to use them.

The action
The MediaWiki web service API implements dozens of actions and extensions implement many more; the dynamically generated API help documents all available actions on a wiki. In this case, we're using the "query" action to get some information. The "query" action is one of the API's most important actions, and it has extensive documentation of its own. What follows is just an explanation of a single example.

Action-specific parameters
The rest of the example URL contains parameters used by the "query" action. Here, we're telling the web service API that we want information about the Wiki page called "Main Page". (The %20 comes from percent-encoding a space.) If you need to query multiple pages, put them all in one request to optimize network and server resources:. See the query documentation for details.

You can request many kinds of information, or properties, about a page. This parameter tells the web service API that we want information about a particular revision of the page. Since we're not specifying any revision information, the API will give us information about the latest revision &mdash; the main page of Wikipedia as it stands right now.

Finally, this parameter tells the web service API that we want the content of the latest revision of the page. If we passed in  instead, we'd get the latest page content and the name of the user who made the most recent revision.

यह केवल एक उदाहरण है। Queries are explained in more detail here, and the API reference lists all the possible actions, all the possible values for, and so on.



चलो शुरू करें
Before you start using the MediaWiki web service API, be sure to read these documents:


 * The FAQ.
 * The page about input and output formats
 * The page about errors and warnings
 * Any policies that apply to the wiki you want to access, such as Wikimedia Foundation wikis' terms of use, trademark policy. These terms apply to you when you access or edit using the API, just as they do when you use your web browser.

Beyond that point, what you need to read depends on what you want to do. The right-hand menu links to detailed, task-specific documentation, and some more general guidelines are given below.

Identifying your client
When you make HTTP requests to the MediaWiki web service API, be sure to specify a  header that properly identifies your client. Don't use the default  provided by your client library, but make up a custom header that identifies your script or service and provides some type of means of contacting you (e.g., an e-mail address).

An example User-Agent string might look like: MyCoolTool/1.1 (https://example.org/MyCoolTool/; MyCoolTool@example.org) BasedOnSuperLib/1.4

On Wikimedia wikis, if you don't supply a  header, or you supply an empty or generic one, your request will fail with an HTTP 403 error (cf. User-Agent policy). Other MediaWiki installations may have similar policies.

If you are calling the API from browser-based JavaScript, you won't be able to influence the  header: the browser will use its own. To work around this, use the  header:

In PHP, you can identify your user-agent with code such as this:

Or if you use cURL:

Logging in
Your client will probably need to log in to MediaWiki, possibly via its own user account. See the login manual page for details.

API etiquette
Please also read: API:Etiquette

If your requests obtain data that can be cached for a while, you should take steps to cache it, so you don't request the same data over and over again. More information about rate-limiting, concurrency, and general API etiquette can be found at API:Etiquette. Some clients may be able to cache data themselves, but for others (particularly JavaScript clients), this is not possible.

Per the HTTP specification, POST requests cannot be cached. Therefore, whenever you're reading data from the web service API, you should use GET requests, not POST.

Also note that a request cannot be served from cache unless the URL is exactly the same. If you make a request for, and cache the result, then a request for   will not go through the cache — even though MediaWiki returns the same data!

You should take care to normalize the URLs you send to the MediaWiki web service, so that slightly different user input won't cause you to waste time on unnecessary HTTP requests. You can normalize a list of page titles by removing duplicates and sorting the titles alphabetically. Similar techniques will work for other kinds of data.

उपयोगी कड़ी
The menu bar on the right side of this page links to more detailed, task-specific documentation. Here are some links having to do with the API as a whole:
 * The API sandbox available on all Wikimedia wikis makes it easy to try out different actions interactively.
 * [//en.wikipedia.org/w/api.php The API reference] contains automatically-generated descriptions of all actions and parameters.
 * Hook into Wikipedia information using PHP and the MediaWiki API (IBM developerWorks article, 17 May 2011)
 * Hook into Wikipedia using Java and the MediaWiki API (6 April 2012)
 * The API tutorial leads you through hands-on exercises and includes a training video.
 * Mailing list for notifications and questions: API mailing list
 * Low-traffic mailing list for announcements only (all posts to this list are posted to mediawiki-api as well): mediawiki-api-announce
 * View and report API bugs in the MediaWiki-API Phabricator project (When reporting new bugs, don't forget to add MediaWiki-API to Projects)
 * — The current MediaWiki database schema
 * — The current MediaWiki database schema

पूरालेख कड़ियाँ

 * 2006 का एपीआई चर्चा