This is an APi for my shorten url open source web app. I built it using NodeJS.
You will find three branches:
- master using Typescript, REST API and GraphQL, unit test with Jest
- javascript first version of this project using only REST API, witout unit test
- GraphQL converting REST API into GraphQL
- See source code of front-end built with React - https://github.com/alexdisdier/short-url
-
Route to shorten url
- Checking if it's a valid URL
- Checking if it's missing http - https
- Creating in MongoDB new URL object
-
Route to redirect the short url
- Find the short url
- redirect to original url
-
Route to update the number of visits to a url
- Find by id the url
- Increment + 1 the number of visits
shorten-url-api
├── dist
├── src
│ ├── constant
│ ├── app.ts
│ ├── server.ts
│ └── url.ts
├── test
├── .gitignore
├── README.md
├── jest.config.js
├── package.json
└── tsconfig.json
Clone this repository :
git clone https://github.com/alexdisdier/short-url-api.git
cd shorten-url-api
Test different branches:
git checkout javascript
git checkout GraphQL
Start the server:
npm run dev
Test the api:
npm run test:unit
Build the app:
npm run build
Open Postman to test it out. Your data will be saved to MongoDB.
If you're on the graphQl branch, you can use graphiql.
- express
- mongoose
- body-parser
- compression
- helmet
- cors
- uid2
- @types/...