Jump to content

OpenJournal:API: Difference between revisions

From openjournal
No edit summary
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
openjournal uses MediaWiki as a backend for all of its content. Anything that is possible on the [https://www.mediawiki.org/wiki/API:Main_page MediaWiki API] is possible here too.
OpenJournal uses MediaWiki as a backend for all of its content. Anything that is possible on the [https://www.mediawiki.org/wiki/API:Main_page MediaWiki API] is possible here too.
 


== REST API ==
== REST API ==
Line 7: Line 6:


You can see some examples below:
You can see some examples below:
=== Retrieving content ===


<pre>
<pre>
Line 19: Line 20:
<code>User:Alice/Laying a hedge</code>.
<code>User:Alice/Laying a hedge</code>.


== All articles by one user (the underlying MediaWiki call) ==
== Traditional API ==
 
You can still directly call the API in "the MediaWiki way".


Same data the <code>/users/{username}/posts</code> route above returns, and where
Here are some examples
its extra parameters -- excerpts, URLs -- come from, if you want to add your own.
=== All articles by one user  ===


<pre>
<pre>
Line 28: Line 31:
</pre>
</pre>


== One article, as HTML ==
=== One article, as HTML ===


<pre>
<pre>
Line 34: Line 37:
</pre>
</pre>


== One article, as source ==
=== One article, as source ===


<pre>
<pre>
Line 40: Line 43:
</pre>
</pre>


== Every article on the site, newest first ==
=== All articles on the site, newest first ===


<pre>
<pre>
Line 46: Line 49:
</pre>
</pre>


== Excerpts and lead images, for a card or a feed ==
=== Excerpts and lead images, for a card or a feed ===


<pre>
<pre>
Line 52: Line 55:
</pre>
</pre>


== An Atom feed of everything ==
=== An Atom feed of everything ===


<pre>
<pre>
GET /index.php?title=Special:RecentChanges&feed=atom&namespace=2
GET /index.php?title=Special:RecentChanges&feed=atom&namespace=2
</pre>
</pre>
=== An Atom feed of one author ===


One author's feed is the same URL narrowed with <code>&tagfilter=</code> or, more
One author's feed is the same URL narrowed with <code>&tagfilter=</code> or, more
simply, poll <code>list=allpages</code> above.
simply, poll <code>list=allpages</code> above.


== Writing from your own code ==
=== Writing from your own code ===


See [[OpenJournal:API/Recipes]] for worked examples, or the full parameter reference
See the full parameter reference at [[Special:ApiHelp/query]] to harness the full power of the API.
at [[Special:ApiHelp/query]] — it is generated from this wiki's own installed modules,
so it is never out of date.

Latest revision as of 10:07, 13 September 2026

OpenJournal uses MediaWiki as a backend for all of its content. Anything that is possible on the MediaWiki API is possible here too.

REST API

For convenience, OpenJournal abstracts some of the MediaWiki URLs into a more modern RESTful format.

You can see some examples below:

Retrieving content

GET /users/{username}/posts                     all of a user's posts, alphabetical by title
GET /users/{username}/posts/{title}              one post: title, wikitext, last-edited time
GET /users/{username}/posts/{title}?format=html  the same post, rendered to HTML
GET /users/{username}                            redirects to their journal (browsable)

{title} is the part after the slash, with spaces as underscores, e.g. /users/Alice/posts/Laying_a_hedge for User:Alice/Laying a hedge.

Traditional API

You can still directly call the API in "the MediaWiki way".

Here are some examples

All articles by one user

GET /api.php?action=query&list=allpages&apnamespace=2&apprefix=Alice/&format=json

One article, as HTML

GET /rest.php/v1/page/User%3AAlice%2FSome_title/html

One article, as source

GET /rest.php/v1/page/User%3AAlice%2FSome_title

All articles on the site, newest first

GET /api.php?action=query&generator=recentchanges&grcnamespace=2&grclimit=30&format=json

Excerpts and lead images, for a card or a feed

GET /api.php?action=query&prop=extracts|pageimages&exchars=300&explaintext=1&titles=User:Alice/Some_title&format=json

An Atom feed of everything

GET /index.php?title=Special:RecentChanges&feed=atom&namespace=2

An Atom feed of one author

One author's feed is the same URL narrowed with &tagfilter= or, more simply, poll list=allpages above.

Writing from your own code

See the full parameter reference at Special:ApiHelp/query to harness the full power of the API.