Code-Directory-API is a simple API that allows registered users to store and execute single file programs, returning its result, in case the program has some errors the API will return the reason.
- Nest.
- Prisma.
- Postgresql.
$ npm install
This project uses Postgresql
and Prisma
to manage persistence
- Install
Postgresql
if you don't already have it. - Create a new database called
code-directory-api
. - Run
npx prisma migrate deploy
.
# development
$ npm run start
# watch mode
$ npm run start:dev
# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:cov
-
Params:
name
: The name of the user, should be less than 120 characters.email
: The email of the user.passwordHash
: The password of the user, should have at least 8 characters.
-
Request body:
{ "name": "John", "email": "[email protected]", "passwordHash": "secret-password" }
-
Example:
curl -X POST http://localhost:3000/auth/signup -H "Content-Type: application/json" --data '{"name": "John", "email": "[email protected]", "passwordHash": "secret-password"}'
-
Params:
email
: The email of the already registered user.password
: The password of the user already registered user.
-
Request body:
{ "email": "[email protected]", "password": "secret-password" }
-
Example:
-
curl -X POST http://localhost:3000/auth/login -H "Content-Type: application/json" --data '{"email": "[email protected]", "password": "secret-password"}'
-
Response:
{"token":"JWTAuthenticator"}
-
Note! to perform this operation the
JWT
is required.
http://localhost:3000/user/{Id}
-
Param:
Id
: Identifier of an already registered User inUuid
format.
-
Example:
-
curl -X GET http://localhost:3000/user/c0c14376-9faf-4d9b-818b-132405a45628 -H "Authorization: Bearer JWTAuthenticator"
-
Response:
{"email": "[email protected]","name":"John"}
-
Note! to perform this operation the
JWT
is required.
-
Params:
userId
: The identifier of the already authenticated user.name
: The desired name of the file that will be stored.executable
: Base64 string, e.g. the stringY29uc3Qgc3VtID0gMSArIDE7DQpjb25zb2xlLmxvZyhzdW0pOw==
is the base64 of the followingjavascript
code:const sum = 1 + 1; console.log(sum);
language
: An available programming language (onlyjavascript
for the moment).
-
Request body:
{ "userId": "c0c14376-9faf-4d9b-818b-132405a45627", "name": "sum", "executable": "Y29uc3Qgc3VtID0gMSArIDE7DQpjb25zb2xlLmxvZyhzdW0pOw==", "language": "javascript" }
-
Example:
-
curl -X POST http://localhost:3000/user/program \ -H "Content-Type: application/json" \ -H "Authorization: Bearer JWTAuthenticator" \ --data '{"userId": "c0c14376-9faf-4d9b-818b-132405a45627", "name": "sum", "executable": "Y29uc3Qgc3VtID0gMSArIDE7DQpjb25zb2xlLmxvZyhzdW0pOw==", "language": "javascript"}'
-
Response:
{"programName":"sum","language":"javascript","result":"2"}
-
-
Allow users to execute already stored programs.
-
Dockerize the project.
-
Add support to more programming languages:
- Python.
- Elixir.
- Rust. 🤔
-
Store the users program files in AWS S3. 🫣