API Model Defintions
up vote
2
down vote
favorite
Typically when I am making API calls I am using javascript (ajax). JSON doesn't include value types of properties, and so everything is passed as a string.
Since I manage my own API I create request-able models that will tell you the definition of a model.
For example Id value type is int, StartDate value type is date.
I use the property types to automate form creation.
Is there a standard as to how to do this? My way works, but I'd prefer to be doing this by the book if it already exists.
api
add a comment |
up vote
2
down vote
favorite
Typically when I am making API calls I am using javascript (ajax). JSON doesn't include value types of properties, and so everything is passed as a string.
Since I manage my own API I create request-able models that will tell you the definition of a model.
For example Id value type is int, StartDate value type is date.
I use the property types to automate form creation.
Is there a standard as to how to do this? My way works, but I'd prefer to be doing this by the book if it already exists.
api
JSON Schema maybe?
– JB Nizet
Nov 8 at 23:31
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
Typically when I am making API calls I am using javascript (ajax). JSON doesn't include value types of properties, and so everything is passed as a string.
Since I manage my own API I create request-able models that will tell you the definition of a model.
For example Id value type is int, StartDate value type is date.
I use the property types to automate form creation.
Is there a standard as to how to do this? My way works, but I'd prefer to be doing this by the book if it already exists.
api
Typically when I am making API calls I am using javascript (ajax). JSON doesn't include value types of properties, and so everything is passed as a string.
Since I manage my own API I create request-able models that will tell you the definition of a model.
For example Id value type is int, StartDate value type is date.
I use the property types to automate form creation.
Is there a standard as to how to do this? My way works, but I'd prefer to be doing this by the book if it already exists.
api
api
asked Nov 8 at 23:24
Tom Crosman
113
113
JSON Schema maybe?
– JB Nizet
Nov 8 at 23:31
add a comment |
JSON Schema maybe?
– JB Nizet
Nov 8 at 23:31
JSON Schema maybe?
– JB Nizet
Nov 8 at 23:31
JSON Schema maybe?
– JB Nizet
Nov 8 at 23:31
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
OpenAPI is a standard you could follow. If you also make use of Swagger, it will allow you to produce a JSON schema which can be used in generating forms.
Thanks for the response. I use Swagger, and I can see the definitions in the swagger client, but I believe those are generated server side. Swagger is only accessible through the client, so I don't believe you can hit swagger with an http call unless there is something i'm unaware of.
– Tom Crosman
Nov 8 at 23:35
I haven't used this before but this should allow you to fetch swagger definitions: github.com/swagger-api/swagger-js
– Eamon Scullion
Nov 8 at 23:43
Sorry, I didn't look through all the documentation, but did OpenAPI have a standard you saw for this specifically?
– Tom Crosman
Nov 9 at 0:26
add a comment |
up vote
1
down vote
The hard part is typings are done at compilation and JS does that in browser.
You could use a typing model agent such as graphQL that adds a definition for those types ahead of time. Those definitions can then be dynamically fetched and enforced using typescript and a tool like apollo.
If you dont want to use typescript or graphql you could use something like mongoose schema and expose the schema on an endpoint then have your front end rebuild the schema dynamically to check types by casting when creating new objects.
Personally ive done this old fashion way by writing my own form schema and enforce the form types strictly on the front end by interpreting the fieldTypes
// returned from API somewhere
const fields = [
type: 'input',
name: 'firstName'
rank: 0,
validation: '/^[a-zA-Zs]+$/'
]
Edit:
Found this great library that exports typed interfaces based on graphQL models.
https://github.com/avantcredit/gql2ts
Yeah it can be done on the front end. However I don't believe Interturd Explorer can handle data types in javascript :/
– Tom Crosman
Nov 9 at 0:23
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
OpenAPI is a standard you could follow. If you also make use of Swagger, it will allow you to produce a JSON schema which can be used in generating forms.
Thanks for the response. I use Swagger, and I can see the definitions in the swagger client, but I believe those are generated server side. Swagger is only accessible through the client, so I don't believe you can hit swagger with an http call unless there is something i'm unaware of.
– Tom Crosman
Nov 8 at 23:35
I haven't used this before but this should allow you to fetch swagger definitions: github.com/swagger-api/swagger-js
– Eamon Scullion
Nov 8 at 23:43
Sorry, I didn't look through all the documentation, but did OpenAPI have a standard you saw for this specifically?
– Tom Crosman
Nov 9 at 0:26
add a comment |
up vote
1
down vote
OpenAPI is a standard you could follow. If you also make use of Swagger, it will allow you to produce a JSON schema which can be used in generating forms.
Thanks for the response. I use Swagger, and I can see the definitions in the swagger client, but I believe those are generated server side. Swagger is only accessible through the client, so I don't believe you can hit swagger with an http call unless there is something i'm unaware of.
– Tom Crosman
Nov 8 at 23:35
I haven't used this before but this should allow you to fetch swagger definitions: github.com/swagger-api/swagger-js
– Eamon Scullion
Nov 8 at 23:43
Sorry, I didn't look through all the documentation, but did OpenAPI have a standard you saw for this specifically?
– Tom Crosman
Nov 9 at 0:26
add a comment |
up vote
1
down vote
up vote
1
down vote
OpenAPI is a standard you could follow. If you also make use of Swagger, it will allow you to produce a JSON schema which can be used in generating forms.
OpenAPI is a standard you could follow. If you also make use of Swagger, it will allow you to produce a JSON schema which can be used in generating forms.
answered Nov 8 at 23:33
Eamon Scullion
682313
682313
Thanks for the response. I use Swagger, and I can see the definitions in the swagger client, but I believe those are generated server side. Swagger is only accessible through the client, so I don't believe you can hit swagger with an http call unless there is something i'm unaware of.
– Tom Crosman
Nov 8 at 23:35
I haven't used this before but this should allow you to fetch swagger definitions: github.com/swagger-api/swagger-js
– Eamon Scullion
Nov 8 at 23:43
Sorry, I didn't look through all the documentation, but did OpenAPI have a standard you saw for this specifically?
– Tom Crosman
Nov 9 at 0:26
add a comment |
Thanks for the response. I use Swagger, and I can see the definitions in the swagger client, but I believe those are generated server side. Swagger is only accessible through the client, so I don't believe you can hit swagger with an http call unless there is something i'm unaware of.
– Tom Crosman
Nov 8 at 23:35
I haven't used this before but this should allow you to fetch swagger definitions: github.com/swagger-api/swagger-js
– Eamon Scullion
Nov 8 at 23:43
Sorry, I didn't look through all the documentation, but did OpenAPI have a standard you saw for this specifically?
– Tom Crosman
Nov 9 at 0:26
Thanks for the response. I use Swagger, and I can see the definitions in the swagger client, but I believe those are generated server side. Swagger is only accessible through the client, so I don't believe you can hit swagger with an http call unless there is something i'm unaware of.
– Tom Crosman
Nov 8 at 23:35
Thanks for the response. I use Swagger, and I can see the definitions in the swagger client, but I believe those are generated server side. Swagger is only accessible through the client, so I don't believe you can hit swagger with an http call unless there is something i'm unaware of.
– Tom Crosman
Nov 8 at 23:35
I haven't used this before but this should allow you to fetch swagger definitions: github.com/swagger-api/swagger-js
– Eamon Scullion
Nov 8 at 23:43
I haven't used this before but this should allow you to fetch swagger definitions: github.com/swagger-api/swagger-js
– Eamon Scullion
Nov 8 at 23:43
Sorry, I didn't look through all the documentation, but did OpenAPI have a standard you saw for this specifically?
– Tom Crosman
Nov 9 at 0:26
Sorry, I didn't look through all the documentation, but did OpenAPI have a standard you saw for this specifically?
– Tom Crosman
Nov 9 at 0:26
add a comment |
up vote
1
down vote
The hard part is typings are done at compilation and JS does that in browser.
You could use a typing model agent such as graphQL that adds a definition for those types ahead of time. Those definitions can then be dynamically fetched and enforced using typescript and a tool like apollo.
If you dont want to use typescript or graphql you could use something like mongoose schema and expose the schema on an endpoint then have your front end rebuild the schema dynamically to check types by casting when creating new objects.
Personally ive done this old fashion way by writing my own form schema and enforce the form types strictly on the front end by interpreting the fieldTypes
// returned from API somewhere
const fields = [
type: 'input',
name: 'firstName'
rank: 0,
validation: '/^[a-zA-Zs]+$/'
]
Edit:
Found this great library that exports typed interfaces based on graphQL models.
https://github.com/avantcredit/gql2ts
Yeah it can be done on the front end. However I don't believe Interturd Explorer can handle data types in javascript :/
– Tom Crosman
Nov 9 at 0:23
add a comment |
up vote
1
down vote
The hard part is typings are done at compilation and JS does that in browser.
You could use a typing model agent such as graphQL that adds a definition for those types ahead of time. Those definitions can then be dynamically fetched and enforced using typescript and a tool like apollo.
If you dont want to use typescript or graphql you could use something like mongoose schema and expose the schema on an endpoint then have your front end rebuild the schema dynamically to check types by casting when creating new objects.
Personally ive done this old fashion way by writing my own form schema and enforce the form types strictly on the front end by interpreting the fieldTypes
// returned from API somewhere
const fields = [
type: 'input',
name: 'firstName'
rank: 0,
validation: '/^[a-zA-Zs]+$/'
]
Edit:
Found this great library that exports typed interfaces based on graphQL models.
https://github.com/avantcredit/gql2ts
Yeah it can be done on the front end. However I don't believe Interturd Explorer can handle data types in javascript :/
– Tom Crosman
Nov 9 at 0:23
add a comment |
up vote
1
down vote
up vote
1
down vote
The hard part is typings are done at compilation and JS does that in browser.
You could use a typing model agent such as graphQL that adds a definition for those types ahead of time. Those definitions can then be dynamically fetched and enforced using typescript and a tool like apollo.
If you dont want to use typescript or graphql you could use something like mongoose schema and expose the schema on an endpoint then have your front end rebuild the schema dynamically to check types by casting when creating new objects.
Personally ive done this old fashion way by writing my own form schema and enforce the form types strictly on the front end by interpreting the fieldTypes
// returned from API somewhere
const fields = [
type: 'input',
name: 'firstName'
rank: 0,
validation: '/^[a-zA-Zs]+$/'
]
Edit:
Found this great library that exports typed interfaces based on graphQL models.
https://github.com/avantcredit/gql2ts
The hard part is typings are done at compilation and JS does that in browser.
You could use a typing model agent such as graphQL that adds a definition for those types ahead of time. Those definitions can then be dynamically fetched and enforced using typescript and a tool like apollo.
If you dont want to use typescript or graphql you could use something like mongoose schema and expose the schema on an endpoint then have your front end rebuild the schema dynamically to check types by casting when creating new objects.
Personally ive done this old fashion way by writing my own form schema and enforce the form types strictly on the front end by interpreting the fieldTypes
// returned from API somewhere
const fields = [
type: 'input',
name: 'firstName'
rank: 0,
validation: '/^[a-zA-Zs]+$/'
]
Edit:
Found this great library that exports typed interfaces based on graphQL models.
https://github.com/avantcredit/gql2ts
edited Nov 12 at 18:26
answered Nov 9 at 0:06
d3l33t
66049
66049
Yeah it can be done on the front end. However I don't believe Interturd Explorer can handle data types in javascript :/
– Tom Crosman
Nov 9 at 0:23
add a comment |
Yeah it can be done on the front end. However I don't believe Interturd Explorer can handle data types in javascript :/
– Tom Crosman
Nov 9 at 0:23
Yeah it can be done on the front end. However I don't believe Interturd Explorer can handle data types in javascript :/
– Tom Crosman
Nov 9 at 0:23
Yeah it can be done on the front end. However I don't believe Interturd Explorer can handle data types in javascript :/
– Tom Crosman
Nov 9 at 0:23
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53217661%2fapi-model-defintions%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
JSON Schema maybe?
– JB Nizet
Nov 8 at 23:31