Pack-Man
API Reference

Analyze Packages

Endpoint for dependency analysis

Analyze Packages

Analyzes a dependency file and returns information about the update status of each package.

Endpoint

POST /api/analyze-packages

Content-Type

application/json

Request Parameters

ParameterTypeRequiredDescription
contentstring✅ YesContent of the dependency file
fileNamestring❌ NoFile name (used for automatic type detection)

Request Example

curl -X POST http://localhost:3000/api/analyze-packages \
  -H "Content-Type: application/json" \
  -d '{
    "content": "{\"dependencies\": {\"react\": \"^18.0.0\", \"next\": \"^13.0.0\"}}",
    "fileName": "package.json"
  }'
const analyzePackages = async (content, fileName) => {
  try {
    const response = await fetch('http://localhost:3000/api/analyze-packages', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({ content, fileName })
    });

    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }

    const data = await response.json();
    return data;
  } catch (error) {
    console.error('Error analyzing packages:', error);
    throw error;
  }
};

// Usage
const packageJson = JSON.stringify({
  dependencies: {
    "react": "^18.0.0",
    "next": "^13.0.0"
  }
});

analyzePackages(packageJson, 'package.json')
  .then(result => console.log(result))
  .catch(error => console.error(error));
import requests
import json

def analyze_packages(content, file_name=None):
    url = 'http://localhost:3000/api/analyze-packages'
    payload = {
        'content': content,
        'fileName': file_name
    }

    try:
        response = requests.post(url, json=payload)
        response.raise_for_status()
        return response.json()
    except requests.exceptions.RequestException as e:
        print(f"Error analyzing packages: {e}")
        raise

# Usage
requirements_content = """Django==4.1.0
requests>=2.28.0
numpy==1.24.0"""

result = analyze_packages(requirements_content, 'requirements.txt')
print(json.dumps(result, indent=2))

Response

Success (200 OK)

{
  "packages": [
    {
      "name": "react",
      "currentVersion": "^18.0.0",
      "latestVersion": "18.2.0",
      "status": "outdated",
      "packageManager": "npm",
      "description": "React is a JavaScript library for building user interfaces.",
      "homepage": "https://reactjs.org/"
    },
    {
      "name": "next",
      "currentVersion": "^13.0.0",
      "latestVersion": "14.1.0",
      "status": "outdated",
      "packageManager": "npm",
      "description": "The React Framework",
      "homepage": "https://nextjs.org"
    }
  ],
  "summary": {
    "total": 2,
    "upToDate": 0,
    "outdated": 2,
    "errors": 0
  }
}

Response Structure

PackageInfo Object

FieldTypeDescription
namestringPackage name
currentVersionstringCurrent version specified in the file
latestVersionstringLatest available version
statusstringStatus: "up-to-date", "outdated" or "error"
packageManagerstringManager: "npm", "pip" or "pub"
descriptionstringPackage description (optional)
homepagestringPackage homepage URL (optional)

Summary Object

FieldTypeDescription
totalnumberTotal packages analyzed
upToDatenumberUp-to-date packages
outdatednumberOutdated packages
errorsnumberPackages with verification errors

Status Codes

CodeDescription
200Analysis completed successfully
400Invalid parameters or malformed content
500Internal server error

Error Examples

Missing content (400)

{
  "error": "Content is required"
}

Parsing failure (400)

{
  "error": "Failed to parse file content"
}

Internal error (500)

{
  "error": "Internal server error"
}

Supported File Formats

package.json

{
  "dependencies": {
    "react": "^18.0.0",
    "next": "^13.0.0"
  },
  "devDependencies": {
    "typescript": "^4.9.0"
  }
}

requirements.txt

Django==4.1.0
requests>=2.28.0
numpy==1.24.0

pubspec.yaml

dependencies:
  flutter:
    sdk: flutter
  http: ^0.13.5

dev_dependencies:
  flutter_test:
    sdk: flutter

Common Errors

Content is required

Cause: The content field was not provided in the request.

Solution: Make sure to include the file content in the request body.

Failed to parse file content

Cause: The provided content is not in a valid format.

Solution: Verify that the content is in the correct format (JSON for package.json, text for requirements.txt, YAML for pubspec.yaml).

Internal server error

Cause: Internal server error, possibly related to communication with package registries.

Solution: Try again after a few seconds. If the problem persists, check your internet connectivity.

Package status 'error'

Cause: Unable to retrieve information about the latest package version.

Possible reasons:

  • Package does not exist in the registry
  • Connectivity issues
  • Incorrect package name

On this page