I鈥檓 considering sending the api/web endpoints in the API, mostly so I can simplify the table formatters (just use the passed url instead of building URLs on the fly in the table formatters based on ID) - but not sure whether that鈥檚 something folks using the API would find useful, whether they would need api endpoints, web endpoints, both, etc.
I have a feature branch with a rough version of this, where the returned results would look like this for an asset:
{
"id": 3,
"name": "",
"asset_tag": "FOO7575222091",
"serial": "dc1a4d40-5cd6-366f-8c7e-25b77bb6a52c",
"model": {
"id": 1,
"name": "Macbook Pro 13"",
"endpoints": {
"api": "https://snipe-it.dev:1337/api/v1/models/1",
"web": "https://snipe-it.dev:1337/models/1"
}
},
"model_number": "4532579729813",
"eol": {
"date": "2020-04-26",
"formatted": "Sun Apr 26, 2020"
},
"status_label": {
"id": 1,
"name": "Deployed",
"status_meta": "deployed"
},
"category": {
"id": 1,
"name": "Laptops",
"visible": true
},
"manufacturer": {
"id": 1,
"name": "Apple",
"visible": true,
"endpoints": {
"api": null,
"web": null
}
},
"supplier": {
"id": 1,
"name": "Johnson LLC",
"visible": true,
"endpoints": {
"api": "https://snipe-it.dev:1337/api/v1/suppliers/1",
"web": "https://snipe-it.dev:1337/suppliers/1"
}
},
"notes": "Created by DB seeder",
"order_number": "667666",
"company": {
"endpoints": {
"api": null,
"web": null
}
},
"location": {
"id": 9,
"name": "Mauricemouth",
"endpoints": {
"api": "https://snipe-it.dev:1337/api/v1/locations/9",
"web": "https://snipe-it.dev:1337/locations/9"
}
},
"rtd_location": {
"id": 1,
"name": "Ahmadside",
"endpoints": {
"api": null,
"web": null
}
},
"image": "https://snipe-it.dev:1337/uploads/models/1-screen-shot-2017-11-30-at-15217-pmpng.png",
"assigned_to": {
"id": 9,
"name": "Mauricemouth",
"type": "location"
},
"warranty_months": null,
"warranty_expires": null,
"created_at": {
"datetime": "2017-11-22 05:28:03",
"formatted": "Wed Nov 22, 2017 5:28AM"
},
"updated_at": {
"datetime": "2017-11-24 11:24:41",
"formatted": "Fri Nov 24, 2017 11:24AM"
},
"deleted_at": null,
"purchase_date": {
"date": "2017-04-26",
"formatted": "Wed Apr 26, 2017"
},
"last_checkout": null,
"expected_checkin": null,
"purchase_cost": "1.00",
"user_can_checkout": false,
"custom_fields": {
"Test Alpha Numeric": {
"field": "_snipeit_test_alpha_numeric_5",
"value": null,
"field_format": "ALPHA-NUMERIC"
},
"Foo": {
"field": "_snipeit_foo_6",
"value": null,
"field_format": "ANY"
},
"lkjlkjljlj": {
"field": "_snipeit_lkjlkjljlj_7",
"value": null,
"field_format": "ALPHA-DASH"
},
"Custom Stuff": {
"field": "_snipeit_custom_stuff_8",
"value": null,
"field_format": "regex:/^[0-9]{15}$/"
},
"Up-sized bifurcated solution": {
"field": "_snipeit_up_sized_bifurcated_solution_1",
"value": null,
"field_format": "IP"
}
},
"available_actions": {
"checkout": true,
"checkin": true,
"clone": true,
"restore": false,
"update": true,
"delete": true
}
}
Thoughts? Would love any feedback from the handful of people who have started messing with the API.
I could see how web endpoint could be useful, I鈥檓 working on some reports to compare my AD objects with assets, and I could use the endpoints for links in the report. You鈥檝e got my vote for it.
Looks a lot like HATEOAS to me, so I'd suggest a more standardized approach to me (even if there is no actual standard):
Here an example:
"model": {
"id": 1,
"name": "Macbook Pro 13"",
"links": {
"self": "https://snipe-it.dev:1337/api/v1/models/1",
"web": "https://snipe-it.dev:1337/models/1"
}
}
At least the links>self is available so applications will be able to automatically navigate trough the entire API.
I wish we'll have soon a standard for this, way simpler to build clients based on that 馃槂
Edit: By the way, not sure if it's interesting to add the information when the value is null from my point of view. I mean that
"rtd_location": {
"id": 1,
"name": "Ahmadside",
"endpoints": {
"api": null,
"web": null
}
},
is similar to that
"rtd_location": {
"id": 1,
"name": "Ahmadside"
},
Indeed one is wasting bandwidth for nothing so you know what I'd have 鈿★笍
@glureau Thanks for the feedback :)
I'm familiar with HATEOAS, but also lots of API methodologies use something similar, even gross ones like HyperMedia. The question isn't what my options are, but rather how helpful will they be for the people consuming the API. I know lots of people are just cobbling together some bash scripts to handle some interfacing between monitoring agents, LDAP, but, but some are stuck using Java or other more rigid systems.