npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

la-seine

v0.0.7

Published

Simple api request library with rate limit management.

Downloads

2

Readme

La Seine

Simple 42 api async request library with rate limit management.

Advantages of using La Seine

Asynchronous Request

Some of 42 api endpoints are very slow. For example, '/scale_teams' endpoint needs more than 10 seconds in one request! So, if you send requests synchronously, it'll take incredibly long time.

---
title: Synchronous Request
---
flowchart LR
  R1[Send First Request] --> W1[Wait First Response] --> R2[Send Second Request] --> W2[Wait Second Response] --> R3[Send Third Request] --> W3[Wait Thrid Response]

Let's assume that single request - response takse 10 seconds. Above example, you'll need to wait more than 30 seconds. But if you send requests asynchronously, you can save much time.

---
title: Asynchronous Request
---
flowchart LR
  R1[Send First Request] --> R2[Send Second Request] --> R3[Send Third Request] --> W[Wait All Responses]

With asynchronous approach, you just need to wait about 10 seconds!

Rate Limit Management

But still, you need to consider about rate limits. Means you can't just send all requests at once. La Seine manages this for you, so you don't need to care about limits when sending requests.

Multiple Api Client Support

La Seine supports multiple api clients. You can add multiple clients to La Seine, and La Seine will pick client automatically during request.

Auto Abort System

Assume you are sending requests to non-existing url. Api server will send 404 status response for each time, and this is neither good to 42 api server nor our application. In this case, La Seine aborts all pending requests and return results. The SeineResult will return the fulfilled responses in responses property form. (See below example.)

Install

npm i la-seine

or

pnpm add la-seine

Usage Example

import seine from 'la-seine';

const seineRequestExample = async () => {
  // 1. Add api client. (You can add mutliple clients here.)
  await seine.addApiClient({
    clientId: 'id-string',
    clientSecret: 'secret-string',
  });

  // 2. Add requests
  for (let i = 0; i < 40; i++) {
    seine.addRequest(
      `https://api.intra.42.fr/v2/scale_teams?page[number]=${i + 1}`,
    );
  }

  // 3. Await for results.
  const result = await seine.getResult();

  // 4. Check result status and use data as you want.
  if (result.status === 'success') {
    // All requests are successfully done.
    for (const response of result.responses) {
      const data = await response.json();
      console.log(data);
    }
  } else {
    // Check for partial successful requests.
    if (result.responses) {
      for (const response of result.responses) {
        const data = await response.json();
        console.log(data);
      }

    // Log for failed requests.
    for (const failedRequest of result.failedRequests) {
      console.log(failedRequest.url, failedRequest.error);
    }
    }
  }
};