sxcu.api
TypeScript icon, indicating that this package has built-in type declarations

2.0.5 • Public • Published

sxcu.api

sxcu.api

Node.js library to interact with the sxcu.net API. (A cli is also included!)

sxcu.api was created to allow any developer of any skill set to easily create images, links, etc on sxcu.net without the hassle of learning the sxcu.net documentation directly.

This module has 0 dependencies. (excluding dev) Check for yourself!

Links

sxcu.api: Docs / Github / npm

sxcu.net: Website / API Docs / Discord / Donate

Updating to v2.0.0 from v1.x.x

The guide for doing so can be found here.

Installation

You can install sxcu.api using npm.

npm install sxcu.api

Example Usage

Here is an example of uploading a file.

// Import the package.
import * as sxcu from 'sxcu.api';

// Set the request user agent to the default.
// This will be done for you on the first request if you don't do it yourself.
sxcu.UserAgent.useDefault();

// Upload the file and log the response.
sxcu.uploadFile('image.png')
    .then((response) => console.log(response))
    .catch((err) => console.log(err));

In v2.0.0 we made the switch to ESM and TypeScript. However, we still support CommonJS.

// Use CommonJS's require method.
const { uploadFile, UserAgent, categorizeImports } = require('sxcu.api');

UserAgent.useDefault();

uploadFile('your-img')
    .then((response) => console.log(response))
    .catch((err) => console.log(err));

If you preferred categorized imports, then you can use categorizeImports. This works with ESM and CommonJS.

// Import the package.
import { categorizeImports } from 'sxcu.api';

// Categorize imports.
const sxcu = categorizeImports();

// Set the request user agent to the default.
sxcu.userAgent.useDefault();

// Upload the file and log the response.
sxcu.files
    .uploadFile('image.png')
    .then((response) => console.log(response))
    .catch((err) => console.log(err));

Respecting rate limits has been made extremely easy, all you need to do is enable the request queue.

// Import methods.
import { toggleRequestQueue } from 'sxcu.api';

// Enable the request queue.
toggleRequestQueue(true, true);

Need to make a custom request? It's pretty simple as well. The request method allows you to make requests that respect rate limits as well (as long as toggleRequestQueue is used beforehand).

// Import methods.
import { request, toggleRequestQueue } from 'sxcu.api';

// Enable the request queue.
toggleRequestQueue(true, true);

// Create your own request.
const response = await request({
    type: 'GET',
    statusErrors: [400, 429],
    baseUrl: 'https://sxcu.net/api/',
    path: `files/abc123`,
}).catch((error) => {
    throw resolveError(error);
});

Contributors

jacobhumston
Jacob Humston

Package Sidebar

Install

npm i sxcu.api

Weekly Downloads

104

Version

2.0.5

License

MIT

Unpacked Size

145 kB

Total Files

71

Last publish

Collaborators

  • jacobhumston