Skip to content

eckyputrady/jsonapicrudexample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSONAPI CRUD Example

The code is heavily inspired from https://github.com/manyminds/api2go/tree/master/examples

Run Tests

go test ./...

Running

go run main.go

Building and running

go build
chmod +x 
./jsonapicrudexample

APIs

Create a new building:
	curl -X POST http://localhost:31415/v0/buildings -d '{"data" : {"type" : "buildings" , "attributes": {"address" : "hello"}}}'

List buildings:
	curl -X GET http://localhost:31415/v0/buildings

List paginated buildings:
	curl -X GET 'http://localhost:31415/v0/buildings?page\[offset\]=0&page\[limit\]=2'
OR
	curl -X GET 'http://localhost:31415/v0/buildings?page\[number\]=1&page\[size\]=2'

Update:
	curl -vX PATCH http://localhost:31415/v0/buildings/1 -d '{ "data" : {"type" : "buildings", "id": "1", "attributes": {"address" : "hello 2"}}}'

Delete:
	curl -vX DELETE http://localhost:31415/v0/buildings/2

Create a floor with the name "UG"
	curl -X POST http://localhost:31415/v0/floors -d '{"data" : {"type" : "floors" , "attributes": {"name" : "UG", "taste": "Very Good"}}}'

Create a building with a floor
	curl -X POST http://localhost:31415/v0/buildings -d '{"data" : {"type" : "buildings" , "attributes": {"address" : "hello"}, "relationships": {"floors": {"data": [{"type": "floors", "id": "1"}]}}}}'

List a buildings floors
	curl -X GET http://localhost:31415/v0/buildings/1/floors

Replace a buildings floors
	curl -X PATCH http://localhost:31415/v0/buildings/1/relationships/floors -d '{"data" : [{"type": "floors", "id": "2"}]}'

Add a floor
	curl -X POST http://localhost:31415/v0/buildings/1/relationships/floors -d '{"data" : [{"type": "floors", "id": "2"}]}'

Remove a floor
	curl -X DELETE http://localhost:31415/v0/buildings/1/relationships/floors -d '{"data" : [{"type": "floors", "id": "2"}]}'

Releases

No releases published

Packages

No packages published

Languages