Comments (6)
Hey @Joshfindit thanks for the feedback. I am 100% behind using UUID's instead of single integers. I tend to do this in any new system I create and I recommend it to everyone who asks for advice. The ID's in SWAPI are integers that just happen to be the primary key too (simplicity back when this was a side project). Interestingly I do get people asking me why certain ones don't exist (for example: #51) and this is because humans see incrementing numbers and assume some logic/relationship there. I do regret doing that, now!
I'm 100% behind someone updating the API so long as backwards compatibility is not affected (we have 100+ integrations and we can't guarantee they are fully HATEOAS and haven't hard-coded anything). Feel free to open a PR and start working on it and I'll be happy to give feedback.
from swapi.
Excellent. If you don't mind, I'll add some notes on this issue; it's interesting enough to keep me coming back and hacking away at it, but I'm a B2C sysadmin turned hobby-dev with some experience in Ruby/Vue.js/Javascript/HTML/CSS, so I might not be the right person to implement it, but who knows I may end up adding Python to the list. :)
from swapi.
Possible avenues to explore (feel free to comment/cherry-pick):
- Add a
UUID
field to all responses - Any objects that do not have a UUID assigned already get one generated when committing to the database
- accept UUIDs on the API endpoints, and do a simple:
if id_from_the_api_call.length == 36:
print "assume UUID"
else:
print "Continue with the current logic"
- One day just return UUIDs as the id for all responses.
Some chance that end-users have hard-coded 8-bit integers as the IDs, but besides that is there any risk to just suddenly returning UUIDs as the ID for all responses? (if the end-user is relating two charaters by querying the API, and they just accept whatever is given as the ID, then it would make no difference whether it refers to22
,8764
, ora7b7f15a-757a-4b46-bc02-ad7b2be7096c
. Same forlist
>query character
.) /v2
the API and do UUID only
from swapi.
Django supports UUID fields by default: https://docs.djangoproject.com/en/1.10/ref/models/fields/#uuidfield
So that's point one resolved :)
Python also has built in uuid checking, so you don't need to do just the length check.
from swapi.
Excellent.
Putting this model code here for reference:
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
Looks like it will automatically generate without any massaging needed.
from swapi.
As for
Python also has built in uuid checking, so you don't need to do just the length check.
Looks like there's a good definition of a function for is_valid_uuid
on Stackoverflow
Basically:
try:
uuid_obj = UUID(uuid_to_test, version=version)
except:
return False
So then:
if is_valid_uuid(id_from_the_api_call):
print "Query the database by UUID"
else:
print "Query the database by integer"
from swapi.
Related Issues (20)
- Search with names. HOT 2
- Add a midi-chlorian count for the Force users
- Height of R2-D2 HOT 3
- Limit results number per page
- Films id does not match url id HOT 1
- SwapiSwift framework
- Does not provide all star wars films HOT 1
- The API is down HOT 1
- The Website is Down HOT 1
- Forked my own verson of SWAPI HOT 7
- swapi.dev - running service HOT 21
- swapi.py4e.com asking for donations?
- SSL Cert
- Swapi
- No heading "https"
- website has gone down in last 12 hours.
- The Website is down again
- Certification expired HOT 3
- No image for api resources
- All schemas return 404 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swapi.