AppStore backend application to interact with Algolia indices.
Requirements: Node >= 7.6 (see why).
- Clone the repo
- Install Node dependencies:
yarn install
- Run the server:
yarn start
- Listening on:
http://0.0.0.0:9000
You can also use npm.
Add an app (as a JSON object) to the Algolia apps
index and return its id
.
Attribute | Type | Format |
---|---|---|
name |
string |
|
category |
string |
|
image |
string |
uri |
link |
string |
uri |
price |
string |
"0.99 USD" |
rating |
integer |
0 <= x <= 5 |
ratingCount |
integer |
0 <= x |
curl --request POST \
--url http://localhost:9000/api/1/apps \
--header 'content-type: application/json' \
--data '{"name": "Reddit", "category": "News", "image": "http://is5.mzstatic.com/image/thumb/Purple7/v4/55/62/4f/55624f73-0bdd-f8ca-d02b-ba5d8fde67ae/source/175x175bb.jpg", "link": "https://itunes.apple.com/us/app/reddit-official-app-trending-news-and-hot-topics/id1064216828", "price": "0 USD", "rating": 5, "ratingCount": 77207}'
16290372
{
"error": {
"code": 400,
"message": "should have required property 'price'",
"url": "https://github.com/francoischalifour/algolia-appstore-backend"
}
}
Delete the app id
from the Algolia apps
index.
curl --request DELETE \
--url http://localhost:9000/api/1/apps/16290372 \
--header 'content-type: application/json'
{
"meta": {
"type": "success",
"code": 200
},
"message": "The app #16290372 was deleted from the Algolia \"apps\" index."
}
Variable | Default | Description |
---|---|---|
APP_SERVER_HOST |
"0.0.0.0" | Address of the server |
APP_SERVER_PORT |
9000 | Port of the server |
ALGOLIA_APP_ID |
"" | Your Algolia app ID |
ALGOLIA_API_KEY |
"" | Your Algolia API key |
To set Algolia's environment variables, duplicate the file .env.sample
and rename it .env
. Provide your Algolia credentials in the latter, which will never be committed.
- Watch:
yarn dev
- Lint:
yarn lint
- Fix lint:
yarn lint:fix
- Test:
yarn test
You can also use npm.
- Server technologies: I decided to use Node and Koa as HTTP framework for this backend implementation. Koa uses
async
andawait
and therefore needs Node >= 7.6. - Architecture: Although this project is meant to be minimalist, I decided to abstract the framework used so that we can easily get rid of Koa and plug another one (see
api/v1/apps/index.js
which abstracts the request and the response forapi/v1/apps/App.js
). - Schema validation: Apps are not sent to Algolia as long as they are not valid apps. I used AJV as JSON-schema validator.
- Routes: I added a
GET /api/1/apps/:id
route for development purpose and better management of theDELETE
route (to check that the object actually exists before deleting it). - Logger: Winston was used to keep track of what the server receives in the console. I decided not to save the logs in a file for this project.
- Code style: Standard JS was used so that I waste time creating a personal custom style.
- Dependency injection: To make testing easier (and mainly for learning purpose), I used Awilix for dependency resolution to mock algoliasearch in test environment.
- Tests: AVA was used for unit tests and integration tests. I mocked algoliasearch to not request Algolia's servers while testing.
MIT © François Chalifour