Documentation ¶
Overview ¶
examples.go shows how to implement a basic CRUD for two data structures with the api2go server functionality. To play with this example server you can run some of the following curl requests
Create a new user:
curl -X POST http://localhost:31415/v0/users -d '{"data" : [{"type" : "users" , "user-name" : "marvin"}]}'
List users:
curl -X GET http://localhost:31415/v0/users
List paginated users:
curl -X GET 'http://localhost:31415/v0/users?page\[offset\]=0&page\[limit\]=2'
OR
curl -X GET 'http://localhost:31415/v0/users?page\[number\]=1&page\[size\]=2'
Update:
curl -vX PATCH http://localhost:31415/v0/users/1 -d '{ "data" : {"type" : "users", "user-name" : "better marvin", "id" : "1"}}'
Delete:
curl -vX DELETE http://localhost:31415/v0/users/2
Create a chocolate with the name sweet
curl -X POST http://localhost:31415/v0/chocolates -d '{"data" : [{"type" : "chocolates" , "name" : "Ritter Sport", "taste": "Very Good"}]}'
Create a user with a sweet
curl -X POST http://localhost:31415/v0/users -d '{"data" : [{"type" : "users" , "user-name" : "marvin", "links": {"sweets": {"linkage": [{"type": "chocolates", "id": "1"}]}}}]}'
Replace a users sweets
curl -X PATCH http://localhost:31415/v0/users/1/links/sweets -d '{"data" : [{"type": "chocolates", "id": "2"}]}'
Add a sweet
curl -X POST http://localhost:31415/v0/users/1/links/sweets -d '{"data" : [{"type": "chocolates", "id": "2"}]}'
Remove a sweet
curl -X DELETE http://localhost:31415/v0/users/1/links/sweets -d '{"data" : [{"type": "chocolates", "id": "2"}]}'
Click to show internal directories.
Click to hide internal directories.