API:Main page/ko


 * 입문자들을 위한 개요입니다. 더 자세한 하위 주제들은 오른쪽 메뉴 에서 보세요.

미디어위키 웹 API는 HTTP 위에서 기능,데이터,메타 데이터로 편리하게 접근할 수 있게 하는 웹 서비스입니다.

소개
"내부 API" 또는 "PHP API"에 관심이 있으시다면, PHP 개발자가 미디어위키에 새로운 기능을 추가할 수 있게 하는 확장 인터페이스를 보세요.

미디어 위키 웹 API는 유지보수를 위해 미디어위키 설치본 모니터링이나 붓을 만드는데 사용됩니다. 미디어위키 데이터베이스에 들어 있는 데이터로의 고수준의, 직접적인 접근을 제공합니다. 클라이언트 프로그램들은 웹 서비스로의 HTTP 요청을 만들어 자동으로 위키에 로그인하고, 데이터를 얻고, 변경 사항을 게시할 수 있습니다. 지원되는 클라이언트들 중에는 붓, Navigation popups과 LiveRC와 같은 가벼운 웹-기반 자바스크립트 클라이언트, Vandal Fighter와 같은 엔드유저 어플리케이션, 그리고 다른 웹 사이트([//tools.wmflabs.org 툴 연구소]' 유틸)등이 있습니다.

새로운 미디어위키 설치본에서 웹서비스는 기본적으로 활성화되어 있으나 관리자가 비활성화 시킬 수 있습니다.

미디어위키는 두 개의 외부에 노출된 인터페이스들을 가집니다.

Special:Export 페이지는 대규모의 위키 콘텐츠를 XML 형태로 내보낼 수 있습니다. 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). Read for information on using the web-based interface.

A simple example
This URL tells English Wikipedia's web service API to send you the content of the main page:

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 format to jsonfm 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. It's like the home page of the MediaWiki web service API. This URL is the base URL for English Wikipedia's API, just as  is the base URL for its web site.

If you're writing a program to use English Wikipedia, every URL you construct will begin with this base URL. 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 format
This tells the Wikimedia web service API that we want data to be returned in JSON format. You might also want to try  to get an HTML version of the result that is good for debugging. Even though the API supports many different output formats such as XML and native PHP, there are plans to remove all formats except for JSON, so you might not want to use them.

The action
This is the 'action'. The MediaWiki web service API supports over fifty actions, and they're all documented in the [//en.wikipedia.org/w/api.php API reference]. In this case, we're using "query" to tell the API that we want to get some data.

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 work with multiple pages, please consider putting them all in one request to optimize network and server resources:. See the query documentation for details.

This parameter tells the web service API that we are interested in 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.

Again, this is just one example. Queries are explained in more detail here, and the API reference lists all the possible actions, all the possible values for, and so on.



Getting started
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 (for Wikimedia Foundation wikis) our terms of use. These terms apply to you when you access or edit using the web service 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 (http://example.com/MyCoolTool/; MyCoolTool@example.com) 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.

Useful links
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: Phabricator (When reporting new bugs, don't forget to set Projects=MediaWiki-API)
 * The current MediaWiki database schema
 * The current MediaWiki database schema

Archived links

 * 2006 API discussion