mirror of
https://github.com/neocities/neocities.git
synced 2025-04-25 01:32:36 +02:00
update API with better examples, complete node.js versions
This commit is contained in:
parent
b4e3f9a643
commit
48ec974195
1 changed files with 34 additions and 16 deletions
|
@ -45,28 +45,18 @@
|
||||||
<p>Upload a single local file (<strong>local.html</strong>), which will be named <strong>hello.html</strong> on your site:</p>
|
<p>Upload a single local file (<strong>local.html</strong>), which will be named <strong>hello.html</strong> on your site:</p>
|
||||||
<code>$ curl -F hello.html=@local.html https://USER:PASS@neocities.org/api/upload</code>
|
<code>$ curl -F hello.html=@local.html https://USER:PASS@neocities.org/api/upload</code>
|
||||||
|
|
||||||
<h6>Using Node.js / Web Browser</h6>
|
<h6>Using Node.js</h6>
|
||||||
<p>This example uses the <a href="https://github.com/neocities/neocities-node" target="_blank">neocities</a> module, which works for node.js and web browsers (via <a href="http://browserify.org" target="_blank">browserify</a>). You can install it by running <strong>npm install neocities --global</strong> in your terminal.</p>
|
<p>This example uses the <a href="https://github.com/neocities/neocities-node" target="_blank">neocities</a> module. You can install it by running <strong>npm install neocities --global</strong> in your terminal.</p>
|
||||||
<pre>
|
<pre>
|
||||||
var NeoCities = require('neocities')
|
var NeoCities = require('neocities')
|
||||||
|
|
||||||
var api = new NeoCities('YOURUSERNAME', 'YOURPASSWORD')
|
var api = new NeoCities('YOURUSERNAME', 'YOURPASSWORD')
|
||||||
|
|
||||||
api.uploadFiles([{
|
api.upload([
|
||||||
name: 'newfileonsite.html'
|
{name: 'hello.html', path: './local.html'}
|
||||||
path: './local.html'
|
], function(resp) {
|
||||||
}], function(resp) {
|
|
||||||
if(resp.result == 'error')
|
|
||||||
throw new Error(resp.error_type+' - '+resp.message)
|
|
||||||
|
|
||||||
// Display response from API
|
|
||||||
console.log(resp)
|
console.log(resp)
|
||||||
})</pre>
|
})</pre>
|
||||||
|
|
||||||
<p>
|
|
||||||
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<h3>POST /api/delete</h3>
|
<h3>POST /api/delete</h3>
|
||||||
<p>
|
<p>
|
||||||
Deletes files from your site. Provide a <strong>filenames</strong> argument with an array of filenames you wish to delete. You can delete any files except index.html.
|
Deletes files from your site. Provide a <strong>filenames</strong> argument with an array of filenames you wish to delete. You can delete any files except index.html.
|
||||||
|
@ -84,6 +74,14 @@ api.uploadFiles([{
|
||||||
curl -d "filenames[]=img1.jpg" -d "filenames[]=img2.jpg" \<br> https://YOURUSER:YOURPASS@neocities.org/api/delete
|
curl -d "filenames[]=img1.jpg" -d "filenames[]=img2.jpg" \<br> https://YOURUSER:YOURPASS@neocities.org/api/delete
|
||||||
</code>
|
</code>
|
||||||
|
|
||||||
|
<h6>Using Node.js</h6>
|
||||||
|
<pre>
|
||||||
|
var NeoCities = require('neocities')
|
||||||
|
var api = new NeoCities('YOURUSERNAME', 'YOURPASSWORD')
|
||||||
|
|
||||||
|
api.delete(['img1.jpg', 'img2.jpg'], function(resp) {
|
||||||
|
console.log(resp)
|
||||||
|
})</pre>
|
||||||
<h3>GET /api/info</h3>
|
<h3>GET /api/info</h3>
|
||||||
<p>
|
<p>
|
||||||
This call lets you retreive information about a web site. This call does not require site authorization if you provide a <strong>sitename</strong> argument. Note that the sitename is the same as a username. If you provide auth credentials, you will receive the info for the auth user's site. Dates conform to <strong>RFC2822</strong> format, and there are helpers for parsing it into a time object for most programming languages.
|
This call lets you retreive information about a web site. This call does not require site authorization if you provide a <strong>sitename</strong> argument. Note that the sitename is the same as a username. If you provide auth credentials, you will receive the info for the auth user's site. Dates conform to <strong>RFC2822</strong> format, and there are helpers for parsing it into a time object for most programming languages.
|
||||||
|
@ -103,8 +101,28 @@ $ curl https://neocities.org/api/info?sitename=youpi
|
||||||
"tags": []
|
"tags": []
|
||||||
}
|
}
|
||||||
}</pre>
|
}</pre>
|
||||||
|
<p>Getting your own site's info:</p>
|
||||||
<code>
|
<code>
|
||||||
$ curl https://YOURUSER:YOURPASS@neocities.org/api/info
|
$ curl https://YOURUSER:YOURPASS@neocities.org/api/info
|
||||||
</code>
|
</code>
|
||||||
|
<h6>Using Node.js</h6>
|
||||||
|
<p>Your site:</p>
|
||||||
|
<pre>
|
||||||
|
var NeoCities = require('neocities')
|
||||||
|
var api = new NeoCities('YOURUSERNAME', 'YOURPASSWORD')
|
||||||
|
|
||||||
|
api.info(function(resp) {
|
||||||
|
console.log(resp)
|
||||||
|
})</pre>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Getting data for a different site - such as the <a href="http://madamfrp.neocities.org" target="_blank">Madam FRP Manual</a>:
|
||||||
|
</p>
|
||||||
|
<pre>
|
||||||
|
var NeoCities = require('neocities')
|
||||||
|
var api = new NeoCities('YOURUSERNAME', 'YOURPASSWORD')
|
||||||
|
|
||||||
|
api.info('madamfrp', function(resp) {
|
||||||
|
console.log(resp)
|
||||||
|
})</pre>
|
||||||
</div> <!-- end .content -->
|
</div> <!-- end .content -->
|
||||||
|
|
Loading…
Add table
Reference in a new issue