Skip to content

This is a Node.js application which uses Turf.js for spatial calculations.

Notifications You must be signed in to change notification settings

Akarsh3053/Intersections-API-turfJS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Intersections API

The Intersections API is a Node.js application that provides an API endpoint for finding intersecting lines between a given line string and a set of randomly spread lines. The API uses Express.js and integrates with the Turf.js library for spatial calculations.

Requirements

  • Node.js (v12 or higher)
  • Postman

Getting Started

  1. Clone the repository:
    git clone https://github.com/Akarsh3053/intersections-API-turfJS
  2. Install the dependencies:
    npm install
  3. Set up environment variables: Create a .env file in the root directory and configure the following variables:
    AUTH_TOKEN="password"
  4. Start the server:
    npm start

The API server will start running on http://localhost:3000.

This endpoint accepts a GeoJSON line string in the request body and finds intersecting lines from the set of randomly spread lines.

Request Body:

{
  "type": "LineString",
  "coordinates": [
    [-96.79512, 32.77823],
    [-96.79469, 32.77832],
    [-96.79433, 32.77728]
  ]
}

Response:

If there are no intersections, the API returns an empty array []. If intersections exist, the API returns an array of objects containing the intersecting line IDs and the intersection points.

Authentication The API endpoint is protected with header-based authentication. Include the Authorization header with the value of the configured authentication token.

Authorization: password

Testing the API with Postman

To test the API using Postman:

  • Launch Postman.
  • Create a new POST request.
  • Set the request URL to http://localhost:3000/api/intersections.
  • Add the Authorization header with the value as password.
  • In the request body, provide a GeoJSON line string in the following format:
{
  "type": "LineString",
  "coordinates": [
    [-96.79512, 32.77823],
    [-96.79469, 32.77832],
    [-96.79433, 32.77728]
  ]
}
  • Send the request and check the response for the intersecting lines.

Tech Used

JavaScript NodeJS Express.js Postman

About

This is a Node.js application which uses Turf.js for spatial calculations.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published