Skip to content

REST API for generating random mathematical expressions.

License

Notifications You must be signed in to change notification settings

cheatsnake/xMath-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⚠️ xMath API is deprecated. Now it is part of Shadify project.

Website GitHub repo size GitHub contributions welcome

🚀 xMath-api

A free API for generating random mathematical expressions.

❔ How to use it?

The API provides you with the ability to get a random expression with mathematical operations such as addition, subtraction, multiplication or division. You get an object containing two numbers, an operation sign, and the result of an expression.

You can choose the operation you need or get a random operation.

🎲 Random expression

https://x-math.herokuapp.com/api/random

➕ Only addition

https://x-math.herokuapp.com/api/add

➖ Only subtraction

https://x-math.herokuapp.com/api/sub

✖️ Only multiplication

https://x-math.herokuapp.com/api/mul

➗ Only division

https://x-math.herokuapp.com/api/div

🔧 Parameters

By default, the range of numbers from 1 to 99 is set for all expressions. But you can adjust the range (for any operation) yourself using the parameters.

Range of generated numbers

The max and min parameters change the possible range for each number in the expression.

?max=999&min=100

The maxFirst and minFirst parameters change the possible range only for the first number (the second number uses the default value).

?maxFirst=256&minFirst=128

The maxSecond and minSecond parameters change the possible range only for the second number (does not affect division, because there the second number is randomly selected from the list of divisors of the first number).

?maxSecond=256&minSecond=128

Negative result

To get expressions that result in negative numbers, you can change the range of values using the parameters described above by adding negative numbers there.

But this will not work for the subtraction operation, because by default there the first number is always greater than the second. To fix this, you can use the parameter negative in the value 1.

https://x-math.herokuapp.com/api/sub?negative=1

❕ Examples

https://x-math.herokuapp.com/api/random?max=999&negative=1
https://x-math.herokuapp.com/api/mul?maxFirst=999&maxSecond=20
https://x-math.herokuapp.com/api/add?max=500&minFirst=100

Available Scripts for Developers

In the project directory, you can:

  • Run the server with Nodemon for development
npm run dev

The page will reload if you make edits.
You will also see any lint errors in the console.
Open http://localhost:5000 to view it in the browser.

  • Launch tests
npm run test
  • Create a production build
npm run build
  • Runs the server of production build
npm start

Open http://localhost:5000 to view it in the browser.