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.










share|improve this question





















  • JSON Schema maybe?
    – JB Nizet
    Nov 8 at 23:31














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.










share|improve this question





















  • JSON Schema maybe?
    – JB Nizet
    Nov 8 at 23:31












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.










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 8 at 23:24









Tom Crosman

113




113











  • 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




JSON Schema maybe?
– JB Nizet
Nov 8 at 23:31












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.






share|improve this answer




















  • 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

















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






share|improve this answer






















  • 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










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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

























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.






share|improve this answer




















  • 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














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.






share|improve this answer




















  • 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












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.






share|improve this answer












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.







share|improve this answer












share|improve this answer



share|improve this answer










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
















  • 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












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






share|improve this answer






















  • 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














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






share|improve this answer






















  • 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












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






share|improve this answer














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







share|improve this answer














share|improve this answer



share|improve this answer








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
















  • 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

















 

draft saved


draft discarded















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)