nanawel / our-shopping-list

OSL is a simple shared list web-application based on Node and VueJS. Typical uses include shopping lists of course, and any other small todo-list that needs to be used collaboratively.
GNU Affero General Public License v3.0
82 stars 8 forks source link

Add an API #21

Closed coredirigent closed 7 months ago

coredirigent commented 7 months ago

Hello,

it would be useful to add an API to OSL.

My use-case: I am using Mealie for recipe management and want to import the shopping list to OSL. Currently i am using a script to add entries directly into the MongoDB. It would be more convenient to be able to use an API to add, modify or delete entries tho.

Thank you for your efforts.

nanawel commented 7 months ago

Hi, Actually the client (the VueJS thing running in the browser) is already communicating with the server though an API. It's not documented, I must agree, but it's simple enough not to require extra presentation imho. It's a simple REST+JSON API.

You can find all the supported endpoints in the server/src/*/routes.js files (example for the lists).

Creating a list is as easy as:

$ curl -X POST --header 'Content-Type: application/json' --data '{"name": "hello"}' 'https://dev.osl.lanterne-rouge.info/lists' | jq
{
  "name": "hello",
  "_id": "205ad557-a403-4a0f-8fe4-18dc996c0571",
  "createdAt": "2023-12-31T10:22:15.471Z",
  "updatedAt": "2023-12-31T10:22:15.471Z",
  "__v": 0,
  "id": "205ad557-a403-4a0f-8fe4-18dc996c0571"
}

Then to retrieve it:

$ curl -s 'https://dev.osl.lanterne-rouge.info/lists/205ad557-a403-4a0f-8fe4-18dc996c0571' | jq
{
  "_id": "205ad557-a403-4a0f-8fe4-18dc996c0571",
  "name": "hello",
  "createdAt": "2023-12-31T10:22:15.471Z",
  "updatedAt": "2023-12-31T10:22:15.471Z",
  "__v": 0,
  "items": [],
  "id": "205ad557-a403-4a0f-8fe4-18dc996c0571"
}

Here I'm using jq to format the JSON output, but it's not a requirement.